node.js 应用程序 运行 在本地很好,但不会 运行 在模数中
node.js app runs fine locally but won't run in modulus
起初,我在 modulus 网站上做了一个 post,但我认为它的社区不是很活跃,所以它包含以下内容:
该应用程序,当我尝试加载它时 URL 会在文档中说出以下任一内容:
未找到
要么
无法收集到任何应用程序实例。
日志里是这么写的,我不是很懂
_http_outgoing.js:335
throw new Error('Can\'t set headers after they are sent.');
^
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:335:11)
at Array.write (/mnt/app/node_modules/express/node_modules/finalhandler/index.js:115:9)
at listener (/mnt/app/node_modules/express/node_modules/on-finished/index.js:164:15)
at onFinish (/mnt/app/node_modules/express/node_modules/on-finished/index.js:95:5)
at callback (/mnt/app/node_modules/express/node_modules/on-finished/node_modules/ee-first/index.js:33:10)
at IncomingMessage.onevent (/mnt/app/node_modules/express/node_modules/on-finished/node_modules/ee-first/index.js:66:5)
at IncomingMessage.emit (events.js:104:17)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)
npm ERR! Linux 3.13.0-46-generic
npm ERR! argv "/mnt/home/.nvm/versions/node/v0.12.4/bin/node" "/mnt/home/.nvm/versions/node/v0.12.4/bin/npm" "start"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! code ELIFECYCLE
npm ERR! socket-Test@1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the socket-Test@1.0.0 start script 'node server.js'.
npm ERR! This is most likely a problem with the socket-Test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node server.js
npm ERR! You can get their info via:
npm ERR! npm owner ls socket-Test
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /mnt/app/npm-debug.log
Found package.json: ./package.json
Start script specified in package.json: node server.js
Initializing Node.js 0.12.4
Now using node v0.12.4
Running command: npm start
> socket-Test@1.0.0 start /mnt/app
> node server.js
listening on *:3000
这一切以前在以相同方式完成的单独项目上都有效,但现在无效。任何建议或解决方案将不胜感激!
(顺便说一句,我不确定这是否正常,但我注意到 node_modules 文件夹不在我的文件列表中,我不确定为什么,因为它在我的本地文件夹中)
但是,现在我已经到了日志会说的地方:
Found package.json: ./package.json
Start script specified in package.json: node server.js
Initializing Node.js 0.12.4
Now using node v0.12.4
Running command: npm start> Space-Wars@1.0.0 start /mnt/app>
node server.js
listening on *:3000
Fri, 29 May 2015 07:07:06 GMT
express deprecated res.sendfile: Use res.sendFile instead at server.js:9:6
Error: ENOENT, stat '/mnt/app/index.html'at Error (native)
Error: ENOENT, stat '/mnt/app/index.html'at Error (native)
我知道它正在 /mnt/app 中查找文件,但我不知道为什么,当它在 运行 本地时,它会在 public 目录中找到所有内容。
我的文件树是这样的:
Public -[
- index.css
- index.js
- index.html
Server.js
node_modules (not included in server, I guess modulus installs based on package.json dependencies)
package.json
我用这个
绑定 public 文件夹
app.use(express.static(path.join(__dirname, 'public')));
谁能帮我解决这个问题,或者至少找到问题所在。谢谢!!
我解决了这个问题,在 express 中我用小写 'public' 绑定了它,所以我将文件夹名称更改为 public 而不是 Public。但是我仍然有点困惑,如果 modulus 使用相同版本的 node.js 模块,为什么它不能在 modulus 的服务器上工作。
起初,我在 modulus 网站上做了一个 post,但我认为它的社区不是很活跃,所以它包含以下内容: 该应用程序,当我尝试加载它时 URL 会在文档中说出以下任一内容:
未找到 要么 无法收集到任何应用程序实例。
日志里是这么写的,我不是很懂
_http_outgoing.js:335
throw new Error('Can\'t set headers after they are sent.');
^
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:335:11)
at Array.write (/mnt/app/node_modules/express/node_modules/finalhandler/index.js:115:9)
at listener (/mnt/app/node_modules/express/node_modules/on-finished/index.js:164:15)
at onFinish (/mnt/app/node_modules/express/node_modules/on-finished/index.js:95:5)
at callback (/mnt/app/node_modules/express/node_modules/on-finished/node_modules/ee-first/index.js:33:10)
at IncomingMessage.onevent (/mnt/app/node_modules/express/node_modules/on-finished/node_modules/ee-first/index.js:66:5)
at IncomingMessage.emit (events.js:104:17)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)
npm ERR! Linux 3.13.0-46-generic
npm ERR! argv "/mnt/home/.nvm/versions/node/v0.12.4/bin/node" "/mnt/home/.nvm/versions/node/v0.12.4/bin/npm" "start"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! code ELIFECYCLE
npm ERR! socket-Test@1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the socket-Test@1.0.0 start script 'node server.js'.
npm ERR! This is most likely a problem with the socket-Test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node server.js
npm ERR! You can get their info via:
npm ERR! npm owner ls socket-Test
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /mnt/app/npm-debug.log
Found package.json: ./package.json
Start script specified in package.json: node server.js
Initializing Node.js 0.12.4
Now using node v0.12.4
Running command: npm start
> socket-Test@1.0.0 start /mnt/app
> node server.js
listening on *:3000
这一切以前在以相同方式完成的单独项目上都有效,但现在无效。任何建议或解决方案将不胜感激!
(顺便说一句,我不确定这是否正常,但我注意到 node_modules 文件夹不在我的文件列表中,我不确定为什么,因为它在我的本地文件夹中)
但是,现在我已经到了日志会说的地方:
Found package.json: ./package.json
Start script specified in package.json: node server.js
Initializing Node.js 0.12.4
Now using node v0.12.4
Running command: npm start> Space-Wars@1.0.0 start /mnt/app>
node server.js
listening on *:3000
Fri, 29 May 2015 07:07:06 GMT
express deprecated res.sendfile: Use res.sendFile instead at server.js:9:6
Error: ENOENT, stat '/mnt/app/index.html'at Error (native)
Error: ENOENT, stat '/mnt/app/index.html'at Error (native)
我知道它正在 /mnt/app 中查找文件,但我不知道为什么,当它在 运行 本地时,它会在 public 目录中找到所有内容。
我的文件树是这样的:
Public -[
- index.css
- index.js
- index.html
Server.js
node_modules (not included in server, I guess modulus installs based on package.json dependencies)
package.json
我用这个
绑定 public 文件夹app.use(express.static(path.join(__dirname, 'public')));
谁能帮我解决这个问题,或者至少找到问题所在。谢谢!!
我解决了这个问题,在 express 中我用小写 'public' 绑定了它,所以我将文件夹名称更改为 public 而不是 Public。但是我仍然有点困惑,如果 modulus 使用相同版本的 node.js 模块,为什么它不能在 modulus 的服务器上工作。