簡體   English   中英

通過browserify在瀏覽器中執行node.js子進程

[英]Execute node.js child process in browser by browserify

我正在使用browserify來使node.js在瀏覽器上運行。 我想執行一個子進程,所以我正在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);
}
}); 

使用browserify命令生成bundle.js

browserify index.js -o bundle.js -d

還包括html中的bundle.js

<script src="bundle.js"></script>

但是在瀏覽器的控制台中

"exec is not a function"

節點版本為v0.12.7

browserify不在瀏覽器中運行node.js。

Browserify允許您在瀏覽器中需要(“模塊”)。

因此您的代碼很整潔。 但是,沒有child_processnetfs

再一次,您不在瀏覽器上運行節點。

PS有一些模塊是用於瀏覽器的net和fs的實現,例如browserify-fs等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM