admin管理员组文章数量:1334190
I am using browserify to get node.js to run on the browser. I want to execute a child process so I am doing something like this in the index.js
var exec = require('child_process').exec;
//I'm just checking the node version installed, you can do your own process here
var ls =exec('node -v', function(error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
A bundle.js is generated using browserify mand
browserify index.js -o bundle.js -d
Also included the bundle.js in html
<script src="bundle.js"></script>
But in the browser's console I am getting as
"exec is not a function"
Node version is v0.12.7
I am using browserify to get node.js to run on the browser. I want to execute a child process so I am doing something like this in the index.js
var exec = require('child_process').exec;
//I'm just checking the node version installed, you can do your own process here
var ls =exec('node -v', function(error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
A bundle.js is generated using browserify mand
browserify index.js -o bundle.js -d
Also included the bundle.js in html
<script src="bundle.js"></script>
But in the browser's console I am getting as
"exec is not a function"
Node version is v0.12.7
Share Improve this question asked Jul 20, 2015 at 6:10 HmahwishHmahwish 2,2328 gold badges27 silver badges45 bronze badges1 Answer
Reset to default 8browserify does NOT run node.js in the browser.
Browserify lets you require('modules') in the browser.
so your code is nice and tidy.
But, there is no child_process
, net
or fs
.
Once again, you are NOT running node on the browser.
P.S. There are modules that are implementations of net and fs for the browser though such as browserify-fs
etc.
本文标签: javascriptExecute nodejs child process in browser by browserifyStack Overflow
版权声明:本文标题:javascript - Execute node.js child process in browser by browserify - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742307802a2450268.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论