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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742307803a4419291.html
评论列表(0条)