I'm trying to deploy my nodejs app but it gives me this error:
2019-11-25T18:16:16.927748+00:00 app[web.1]: > [email protected] 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
I tried other possible solutions posted on StackOverflow but it seems to be not working at all. I get an Application Error each time I deploy my nodejs app.
My package.json file:
{
"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"
}
}
My Procfile: web: node server.js
My server.js code:
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);
It would be really great if anyone can help me up with this issue to resolve nodemon not found error.