我正在尝试部署我的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应用程序时,我都会得到一个Application Error
。
我的package.json
文件:
{
"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"
}
}
我的Procfile
:web: node server.js
我的server.js
代码:
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);
如果有人能帮助我解决此问题来解决nodemon not found
错误,那真是太好了。
答案 0 :(得分:1)
我通过将nodemon
替换为node
解决了这个问题。
正如@JDunken指出的那样,nodemon
是一种开发工具。无法部署。