你的位置:首页 > 互联网IT
node同时运行多个js,nodejs同时运行多个js,同一窗口同时运行多个node.js,node多个同时运行,nodejs同时多个运行,同窗口运行多个js,同一个窗口运行多个nodejs
系统:windoes/linux
软件:nodejs
创建名称:111.js
代码如下:
var exec = require('child_process').exec;
var child = exec('node ' + 'proxy.js 8080 www.baidu.com 80', function(err, stdout, stderr) {
if (err) throw err;
console.log(stdout);
});
var child = exec('node ' + 'proxy.js 8081 www.baidu.com 81', function(err, stdout, stderr) {
if (err) throw err;
console.log(stdout);
});
保存!
启动:
Windows/linux同目录下运行:node 111.js
windows:建立.bat
@echo off
start "" "node" 111.js
需要修改的代码:
var child = exec('node ' + 'proxy.js 8080 www.baidu.com 80', function(err, stdout, stderr)
代码分析:
'node ' + 'proxy.js 8080 www.baidu.com 80'
启动node,proxy.js改成自己的js文件名称, 运行参数: 8080 www.baidu.com 80(没有运行参数,可以删除)如下:
var child = exec('node ' + 'proxy.js', function(err, stdout, stderr)
windows
后台隐藏运行:https://m.012.ooo/?id=520
linux
后台隐藏运行:https://m.012.ooo/?id=498
发表评论: