我正在使用nodejs版本 - v0.10.31
在一台机器上它可以工作,而在我的机器上却没有。有人可以给我一些建议,我可以开始寻找问题吗?
var express = require('express'),
path = require('path'),
fs = require('fs'),
mongoose = require('mongoose'),
expressSession = require("express-session");
var env = process.env.NODE_ENV = process.env.NODE_ENV || "development";
var config = require('./server/config/config')[env];
var app = express();
var server = app.listen(config.port);
var sessionMiddleware = expressSession({
name: "dga-cookie",
secret: "dga-secret",
store: new (require("connect-mongo")(expressSession))({
url: config.db,
auto_reconnect: true
}),
saveUninitialized: true,
resave: true
});
app.use(sessionMiddleware);
var io = require('socket.io')(server);
io.use(function(socket, next){
sessionMiddleware(socket.request, {}, next);
});
require('./server/config/express')(app, config);
require('./server/config/mongoose')(config);
/* user schema */
var userSchema = mongoose.Schema({
username: {type: String, required: true, unique: true},
email: {type: String, required: true, unique: true},
password: {type: String, required: true},
activated: {type: Boolean, required: true}
});
var User = mongoose.model('users', userSchema);
require('./server/config/routes')(app);
require('./server/config/rest/user')(app, io, User);
require('./server/config/rest/game')(app, io, User);
并且有package.json:
{
"name": "app",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/..."
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/..."
},
"homepage": "https://github.com/...",
"dependencies": {
"body-parser": "~1.5.0",
"compass": "~0.1.0",
"connect-mongo": "~0.4.1",
"cookie-parser": "~1.3.2",
"express": "~4.6.1",
"express-session": "~1.7.0",
"jade": "~1.4.2",
"mongoose": "~3.8.13",
"morgan": "~1.2.0",
"node-compass": "^0.2.3",
"passport": "~0.2.0",
"passport-local": "~1.0.0",
"sha1": "^1.1.0"
},
"devDependencies": {
"bower": "~1.3.8",
"socket.io": "~1.0.6"
}
}
$ nodemon server 15 Sep 20:51:36 - [nodemon] v1.2.1 15 Sep 20:51:36 - [nodemon] to restart at any time, enter `rs` 15 Sep 20:51:36 - [nodemon] watching: *.* 15 Sep 20:51:36 - [nodemon] starting `node server` DGE db opened GET / 304 626.838 ms - - events.js:72 throw er; // Unhandled 'error' event ^ Error: spawn ENOENT at errnoException (child_process.js:1001:11) at Process.ChildProcess._handle.onexit (child_process.js:792:34) 15 Sep 20:51:45 - [nodemon] app crashed - waiting for file changes before starting...
答案 0 :(得分:1)
我在Windows 8.1上也遇到了同样的错误。 该错误是由于系统路径的环境变量缺少“C:\ Windows \ System32 \”值。 因此,请右键单击“我的电脑”,转到“属性” - >“高级系统设置” - >“环境”变量。现在打开(编辑)“PATH”变量并将“C:\ Windows \ System32 \”值添加到路径变量的值字段中。保存所有更改。现在关闭Node.js cmd提示符并重新打开它。现在输入nodemon cmd。希望它对你有用。
答案 1 :(得分:0)
这是在GET请求之后发生的。我将查看您的路由文件,并查看该上下文中正在使用的文件。
答案 2 :(得分:0)
我建议您检查机器上是否安装了mongodb(可执行文件,而不是npm)。当节点尝试执行不存在的程序时,通常会发生此错误。
祝你好运!