[英]Node.js spawn ENOENT error
So I followed this answer and made it to the last step, correctly I think. 所以我按照这个答案把它做到了最后一步,我认为正确。 But then what?
但那又怎样? I'm trying to run a node file, but it doesn't appear to be in the file listed at the PATH directory.
我正在尝试运行节点文件,但它似乎不在PATH目录中列出的文件中。 How am I supposed to get it in that folder?
我该如何在该文件夹中获取它?
My node entry file: 我的节点输入文件:
'use strict';
var express = require("express");
var child_process = require("child_process");
var app = express();
app.get("/go", function(req, res, next) {
var stream = child_process.spawn("node file.js").on("error", function(error) {
console.log("Error!!! : " + error);
throw error;
});
});
app.get("/", function(req, res, next) {
console.log("Hit main page.");
res.end("Got me.");
});
app.listen( (process.env.PORT || 4000), function() {
console.log("Example app listening on Heroku port " + process.env.PORT + " or local port 4000!");
});
And file.js, the file I'm attempting to open: 和file.js,我试图打开的文件:
'use strict';
function sayHello() {
console.log("Hello.");
}
sayHello();
In your spawn method, you should have: 在您的spawn方法中,您应该:
app.get("/go", function(req, res, next) {
var stream = child_process.spawn("node", ["file.js"]).on("error", function(error) {
console.log("Error!!! : " + error);
throw error;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.