javascript - Execute node.js child process in browser by browserify - Stack Overflow

I am using browserify to get node.js to run on the browser. I want to execute a child process so I am d

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 badges
Add a ment  | 

1 Answer 1

Reset to default 8

browserify 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742307803a4419291.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信