androllen / KnowlegeRepository

0 stars 0 forks source link

Node.js #15

Open androllen opened 4 years ago

androllen commented 4 years ago

nodejs 官网
nvm github
Node Version Manager (nvm) for Windows
NVM 下载页
NodeJs 安装教程

androllen commented 4 years ago

Js & Python

child_process doc
demo file
json file

demoJsPy->txpy->script.py
demoJsPy->index.js

# index.js
const _reqhost = "tcp://127.0.0.1:5555";
const _subhost = "tcp://127.0.0.1:50505";

const { join } = require('path');
const util = require('util');
const execFile = util.promisify(require('child_process').execFile);
async function getVersion() {
    let dirpath = join(__dirname, 'txpy','script.py');
    const { stdout } = await execFile('python', [dirpath]);
    console.log(stdout);
}

getVersion();
# script
import json
import os

def main():
    path = os.path.dirname(os.path.abspath(__file__))
    path = os.path.join(path,'assets','countries.json')

    data = ''

    # with open(path) as json_data:
    #   json_data.write(data)
    #   json_data.close()

    data= json.load(open(path))
    print(data)

if __name__ == "__main__":
    main()
androllen commented 4 years ago

test.js

let zmq = undefined
try {
    zmq = require('zeromq')
} catch (error) {
    zmq = window.require('zeromq')
}

var path = require('path');
function ZmqJs() {
    this.zeromq = path;
}

ZmqJs.prototype.setType = function (type) {
    var hasAuth = type === 'true'
    console.log(hasAuth);
    console.log(type);
}
ZmqJs.prototype.setWrap = function (wrap) {
    this.wrap = typeof wrap === 'string' ? '1' : '2';
    console.log(this.wrap);
}

module.exports = new ZmqJs();

main.js

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import Element from 'element-ui'
let zmq = require('./service/cdn')
Vue.prototype.zmq = zmq;

Vue.config.productionTip = false
Vue.use(Element)

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')

about.vue

this.zmq.setWrap(".venn");
this.zmq.setType('false');

result: 1 false (typeof boo) false (typeof string)

androllen commented 4 years ago

vscode debug node

androllen commented 4 years ago
var json = [{ "http://www.55.cn/": "999" }, { "http://www.eoemarket.com/soft/735928.html": "555" }]

for (let key in json) {
    for (let i in json[key]) {
        console.log('key:'+ i);
        console.log('value:' +json[key][i]);
    }
}