node.js应用程序在本地运行良好,但不会以模数运行
问题描述:
起初,我在模数网站上发表了一篇文章,但我认为它的社区并不是非常活跃,所以这里是它包含的内容: The应用程序,当我尝试加载它时,URL将会在文档中显示其中的任意一个:node.js应用程序在本地运行良好,但不会以模数运行
未找到 或 无法收集到任何应用程序实例。
在日志中,它是这样说的,我并不真正了解它。
_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! [email protected] start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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
> [email protected] 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> [email protected] 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 /应用程序文件,但我不知道为什么,它在公共目录中发现的一切,当它; S在本地运行。
我的文件树是这个样子:
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
我绑定的公用文件夹这个
app.use(express.static(path.join(__dirname, 'public')));
谁能帮我解决这个问题,或者至少发现问题。谢谢!!
答
我解决了这个问题,我明确表示我用小写的'public'来绑定它,所以我将文件夹名称改为public而不是Public。然而,我仍然有点困惑,如果模数使用相同版本的node.js模块,为什么它不能在模数的服务器上工作。
你不应该写一个大写字母的整个句子。它既不会让你的问题更重要,也不会使标题更具可读性。另外使用大写字母就像大喊大叫。 –
也许您正在使用的折旧功能有些问题?你是否尝试过使用'res.sendFile'而不是'res.sendfile'? **请注意案例**。 – Claies
它是大写,因为我从模数网站复制了它,tniese。 @Claies它不应该,我有另一个模块上使用res.sendfile node.js应用程序,并没有问题,但我会给它一个镜头。是的,没有区别:( – DaMuffiner