test.js
const execFile = require('child_process').execFile;
const child = execFile('python', ['temp.py'], (error, stdout, stderr) => {
if (error) {
throw error;
}
console.log(stdout);
});
node test.js
即可运行上述js文件,运行python脚本,
在Angular2组件中直接使用上述代码是显然不行的,那么在Angular2中时候有办法调用nodejs的API吗?
angular就是运行在浏览器环境里面,不可能调用Node API的。
有一个办法就是 用Electron作为你的浏览器环境,通过直接写桥接代码把Node API暴露给浏览器