【问题标题】:Node.js Chat Room on Heroku Application ErrorHeroku 应用程序错误的 Node.js 聊天室
【发布时间】:2017-08-19 16:40:14
【问题描述】:

加载我的 heroku 页面时出现应用程序错误。我按照这里的说明进行操作https://devcenter.heroku.com/articles/deploying-nodejs

我的代码是这个版本https://enlight.ml/nodejs-chat的调整版本。

我的节点 server.js 文件的一部分。

var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var people = {};
var heads = [];
app.get('/', function(req, res, next) {
    res.sendFile(__dirname + '/public/index.html')
});

server.listen(process.env.PORT || 5000);

heroku 日志。

2017-03-27T05:40:05.790068+00:00 heroku[web.1]: State changed from crashed to starting
2017-03-27T05:40:07.296635+00:00 heroku[web.1]: Starting process with command `node server.js`
2017-03-27T05:40:09.867374+00:00 app[web.1]: module.js:471
2017-03-27T05:40:09.867387+00:00 app[web.1]:     throw err;
2017-03-27T05:40:09.867387+00:00 app[web.1]:     ^
2017-03-27T05:40:09.867388+00:00 app[web.1]: 
2017-03-27T05:40:09.867389+00:00 app[web.1]: Error: Cannot find module 'socket.io'
2017-03-27T05:40:09.867390+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:469:15)
2017-03-27T05:40:09.867390+00:00 app[web.1]:     at Function.Module._load (module.js:417:25)
2017-03-27T05:40:09.867391+00:00 app[web.1]:     at Module.require (module.js:497:17)
2017-03-27T05:40:09.867392+00:00 app[web.1]:     at require (internal/module.js:20:19)
2017-03-27T05:40:09.867392+00:00 app[web.1]:     at Object.<anonymous> (/app/server.js:4:30)
2017-03-27T05:40:09.867393+00:00 app[web.1]:     at Module._compile (module.js:570:32)
2017-03-27T05:40:09.867393+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:579:10)
2017-03-27T05:40:09.867395+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2017-03-27T05:40:09.867394+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2017-03-27T05:40:09.867394+00:00 app[web.1]:     at Module.load (module.js:487:32)
2017-03-27T05:40:09.947727+00:00 heroku[web.1]: State changed from starting to crashed
2017-03-27T05:40:09.928089+00:00 heroku[web.1]: Process exited with status 1

package.json.

{
  "name": "im",
  "version": "1.0.0",
  "description": "Messaging App",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/username/im.git"
  },
  "author": "me",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/username/im/issues"
  },
  "homepage": "https://github.com/username/im#readme",
  "dependencies": {
    "express": "4.15.2"
  },
  "engines": {
    "node": "6.10.0"
   },
  "devDependencies": {},
  "keywords": [
    "chat",
    "app"
  ]

}

.gitignore 文件。

    /node_modules
    npm-debug.log
   .DS_Store
   /*.env

【问题讨论】:

    标签: node.js git heroku socket.io


    【解决方案1】:

    这解决了它。

    npm install socket.io --save 
    git add . 
    git push heroku master
    

    【讨论】:

      【解决方案2】:

      你需要安装socket.io包并保存在package.json中

      npm install socket.io --save
      

      或参考您保存的位置。

      var io = require('../lib/socket.io');
      

      然后使用它。

      【讨论】:

        猜你喜欢
        • 2012-08-11
        • 2014-04-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-23
        • 1970-01-01
        • 1970-01-01
        • 2011-10-30
        相关资源
        最近更新 更多