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

本文标签: javascriptExecute nodejs child process in browser by browserifyStack Overflow