Javascript 在Heroku上部署NodeJS应用程序时遇到错误

Javascript 在Heroku上部署NodeJS应用程序时遇到错误,javascript,node.js,heroku,Javascript,Node.js,Heroku,我正在尝试部署我的nodejs应用程序,但出现以下错误: 2019-11-25T18:16:16.927748+00:00 app[web.1]: > anonymous-forum-discussion@1.0.0 start /app 2019-11-25T18:16:16.927751+00:00 app[web.1]: > nodemon server.js 2019-11-25T18:16:16.927753+00:00 app[web.1]: 2019-11-25T18:

我正在尝试部署我的nodejs应用程序,但出现以下错误:

2019-11-25T18:16:16.927748+00:00 app[web.1]: > anonymous-forum-discussion@1.0.0 start /app
2019-11-25T18:16:16.927751+00:00 app[web.1]: > nodemon server.js
2019-11-25T18:16:16.927753+00:00 app[web.1]:
2019-11-25T18:16:16.935126+00:00 app[web.1]: sh: 1: nodemon: not found
2019-11-25T18:16:16.940397+00:00 app[web.1]: npm ERR! file sh
2019-11-25T18:16:16.940690+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-11-25T18:16:16.940929+00:00 app[web.1]: npm ERR! errno ENOENT
2019-11-25T18:16:16.941180+00:00 app[web.1]: npm ERR! syscall spawn
我尝试了StackOverflow上发布的其他可能的解决方案,但它似乎根本不起作用。每次部署nodejs应用程序时,我都会收到一个应用程序错误

My package.json文件:

我的Procfile:web:node server.js

My server.js代码:


如果有人能帮我解决nodemon未找到错误,那就太好了。

我通过将nodemon替换为node解决了这个问题


正如@JDunken所指出的,nodemon是一个开发工具。它无法部署。

您通常不想部署nodemon,因为它是一个开发工具。只需将nodemon替换为nodeThanks@Udit,就可以了!
{
  "name": "anonymous-forum-discussion",
  "version": "1.0.0",
  "description": "Anonymous Forum Discussion",
  "main": "server.js",
  "scripts": {
    "start": "nodemon server.js",
    "test": "echo \"Error: no test specified\" && exit 1",
    "postinstall": "cd frontend && npm install && npm run build && cd .."
  },
  "dependencies": {
    "body-parser": "^1.19.0",
    "express": "^4.17.1",
    "mongoose": "^4.11.5"
  },
  "devDependencies": {
    "nodemon": "^1.19.4"
  },
  "engines": {
    "node": "10.15.3"
  }
}
var express = require('express');
const path = require('path');

var mongoose = require('mongoose');
var bodyParser = require('body-parser');

var models = require('./api/models/message');

var routes = require('./api/routes/routes');

var port = process.env.PORT || 3001;
var app = express();
var Message = mongoose.model('Message')

mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost/discussion');

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

routes(app);

if (process.env.NODE_ENV === "production") {
  app.use(express.static("frontend/build"));
  console.log("production");
}

app.get('*', function (request, response){
  response.sendFile(path.resolve(__dirname, 'frontend/build', 'index.html'))
});

app.listen(port);

console.log('Server running on port ' + port);