nodemon not able to start nodejs app with express v4 - node.js

There must have some simple solution with this problem. I have created a new project using Webstorm for Express js + Node js. Then i installed nodemon using npm install -g nodemon and it was fine. But when i am trying to start my app using nodemon app.js it is showing only
sany2k8#sany2k8-Aspire-4752:/var/projects/ENStack$ nodemon app.js
[nodemon] 1.9.2
[nodemon] to restart at any time, enter rs [nodemon] watching: .
[nodemon] starting node app.js
[nodemon] clean exit - waiting for changes before restart
package.json
{
"name": "ENStack",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.13.2",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.13.1",
"jade": "~1.11.0",
"morgan": "~1.6.1",
"serve-favicon": "~2.3.0"
}
}
Edit: When i tried with npm start then it is showing bunch of errors
sany2k8#sany2k8-Aspire-4752:/var/projects/ENStack$ npm start
ENStack#0.0.0 start /var/projects/ENStack
node ./bin/www
Port 3000 is already in use

we need to add start with nodemon ./bin/www in the json file and
run your project using: nodemon app
{
"name": "ENStack",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "nodemon ./bin/www"
},
"dependencies": {
"body-parser": "~1.13.2",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.13.1",
"jade": "~1.11.0",
"morgan": "~1.6.1",
"serve-favicon": "~2.3.0"
}
}

Additionally, some times, the port are in use. If the solution above not work for you, try change the port. It may be in use for some other node instance.

Related

Error during uploading mern stack project into heroku

In Procfile:
web: node Backend/server.js
In package.json of backend, I am using post build for react app. its saying cannot find module /app/backend/server.js.
{
"name": "ecommerce",
"version": "1.0.0",
"description": "",
"main": "Backend/server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node backend/server.js",
"dev": "nodemon backend/server.js",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false && npm install --prefix frontend && npm run build --prefix frontend"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"cloudinary": "^1.28.1",
"cookie-parser": "^1.4.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-fileupload": "^1.2.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.0.10",
"nodemailer": "^6.7.0",
"nodemon": "^2.0.13",
"stripe": "^8.197.0",
"validator": "^13.6.0"
}
}
My project is laid out like this:
Backend/
frontend/
Procfile
package-lock.json
package.json
Your start script tries to run node backend/server.js, but your file is actually at Backend/server.js. Heroku's filesystem is case-sensitive. You can use either option, but you must be consistent.
Here is one solution. Rename your directory:
git mv Backend backend
And update your Procfile:
web: node backend/server.js
Then commit and redeploy.

Can't run node express on centos server

I am trying to run an express app that I installed using express --view pug urltracker. I also executed npm install to install all dependencies.
When I start it on my laptop localhost using DEBUG=urltracker:* && npm start
it perfectly starts on localhost:3000 and my app runs smoothly but when I install it on centos 7 server, the same gets stuck at [nodemon] starting `node ./bin/www and nothing happens afterwards.
I tried running it like this as well DEBUG=backend ./bin/www but it says -bash: ./bin/www: Permission denied OR sudo: ./bin/www: command not found
I can execute a normal file like node app.js and it works fine but when it comes to running it as server, it doesn't work.
Here's my package.json
{
"name": "urltracker",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "nodemon ./bin/www"
},
"dependencies": {
"body-parser": "~1.18.2",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.15.5",
"morgan": "~1.9.0",
"pug": "2.0.0-beta11",
"serve-favicon": "~2.4.5",
"puppeteer": "^1.6.2",
"puppeteer-select": "^1.0.3"
},
"devDependencies": {
"eslint-plugin-mocha": "^4.11.0",
"file-system": "^2.2.2",
"jest": "^21.2.1",
"js-comments": "^0.5.4",
"lodash": "^4.17.13"
}
}
I also tried it with running node supervisor using supervisor ./bin/www
but it says
Starting child process with 'node ./bin/www'
Watching directory '/home/admin/web/example.com/node/projects' for changes.
Press rs for restarting the process.
I also tried changing the port to 3001 in ./bin/www like this - server.listen('3001', '0.0.0.0');
but nothing works. Help.
Nodemon is not listed in your dependencies list in package.json and on the centos server nodemon is not present.
Please add the nodemon dependency in the package.json and then run npm i
or change the start script from "start": "nodemon ./bin/www" to "start": "node ./bin/www"

Heroku Deployment Continues to Fail at "Pruning devDependencies" Step

I continue to have issues deploying to Heroku and I can't find out what is going wrong for the life of me. The Heroku error log tells me this after it successfully builds my react app:
-----> Caching build
- node_modules
-----> Pruning devDependencies
npm ERR! Cannot read property 'match' of undefined
Here is my package.json
{
"name": "test",
"version": "1.0.0",
"homepage": "./",
"description": "test",
"main": "server.js",
"node": "v12.13.1",
"npm": "6.13.7",
"scripts": {
"heroku": "node server.js",
"client-install": "npm install --prefix client",
"build": "cd client && react-scripts build",
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"author": "John Doe",
"license": "MIT",
"dependencies": {
"#material-ui/core": "^4.8.0",
"axios": "^0.19.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"classnames": "^2.2.6",
"concurrently": "^5.1.0",
"date-fns": "^2.8.1",
"debug": "^4.1.1",
"depcheck": "^0.9.1",
"eslint-plugin-flowtype": "^4.6.0",
"express": "^4.16.4",
"fibers": "^4.0.2",
"growl": "^1.10.5",
"heroku": "^7.35.1",
"history": "^4.10.1",
"is-empty": "^1.2.0",
"jquery": "^3.4.1",
"jsonwebtoken": "^8.3.0",
"jwt-decode": "^2.2.0",
"material-table": "^1.54.2",
"material-ui": "^0.20.2",
"minimatch": "^3.0.4",
"moment": "^2.23.0",
"mongodb": "^3.5.3",
"mongoose": "^5.8.9",
"mongoose-global": "^1.0.1",
"morgan": "^1.9.1",
"node-sass": "^4.13.0",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"plaid": "^4.6.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-ga": "^2.7.0",
"react-plaid-link-button": "0.0.4",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.3.0",
"react-slick": "^0.25.2",
"react-stripe-elements": "^6.0.1",
"react-vis": "^1.11.7",
"redux-thunk": "^2.3.0",
"sass": "^1.24.0",
"slick": "^1.12.2",
"slick-carousel": "^1.8.1",
"typescript": "^3.7.4",
"update-mongo": "0.0.4",
"validator": "^12.2.0",
"vis": "^4.21.0-EOL"
},
"devDependencies": {},
"engines": {
"node": "12.x"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
What is perhaps most frustrating, is that I was able to deploy successfully once the other day but I am not sure what changed. Going back through my git I can't see anything that would have made any difference.
Things I have tried:
removing package.json
adding "devDependencies": {} to my package.json (although I
deployed successfully without it)
updating node and adding the engines section to my package.json to
match.
running npm prune locally
ensuring that all packages are updated and referenced appropriately in package.json
Things that I suspect could be the issue:
Maybe somehow the current version of my app that is actively deployed on heroku is interfering with my new deployment? That being said i have tried scaling down dynos and deploying. Additionally the npm ERR! Cannot read property 'match' of undefined seems to indicate something else?
Just run into this after my deploys inexplicably started failing after a number of successful ones.
Stopping heroku from caching node_modules seemed to do the trick for me.
heroku config:set NODE_MODULES_CACHE=false
Then git push heroku master
I don't have package-lock.json committed after hearing Heroku doesn't get on well with lockfiles, but wondering if that's the problem.
Please rm -rf node_modules && npm i
also be sure to track package-lock.json file
And as long as you are there, is not related but may be a good idea to add a .nvmrc file
node -v >> .nvmrc
Let us know if it helped
In the scripts section in package.json, only keep the start key and remove others.
Your scripts in the package.json should be,
"scripts": {
"start": "node server.js"
},
Also before deployment, build the react app manually.
Heroku messed up with all these build scripts.

Npm ‘Dev’ Watchify/Browserify/vueify cmd to compile Vue component and start Express server fails? (server fails to start)

I’m following a tutorial https://mindthecode.com/using-vue-components-in-your-express-app/ to use vue components with Express.
Part of that is configuring an npm dev script to compile the vue component with Browserify/vueify, start Watchify, then start the Express Server.
Every step of the turorial worked but the ‘dev’ script doesn't work 100% as the express server doesn't start.
Can anyone help figure how what is wrong or what I need to do to get that script working?
Package.json
"scripts": {
"start": "echo 'server starting on port 3000' & node ./bin/www",
"dev": "watchify -vd -p browserify-hmr -t vueify -e public/javascripts/main.js -o public/javascripts/bundle.js & node ./bin/www"
},
‘npm run dev’ compiles the vue component and starts watchify and the hot reload works if I change the vue component code. HOWEVER, the express server fails to start?
Note:
browserify -t vueify -e public/javascripts/main.js -o public/javascripts/bundle.js – works fine at the command line to compile the .vue files
npm start – works fine and can load page at ‘localhost:3000’
I'm using windows10, node v8.9.4 and some of the relevant dependencies from package.json
"browserify-hmr": "^0.3.5",
"express": "~4.14.0",
"vue": "^2.5.0",
"vueify": "^9.4.1",
"watchify": "^3.9.0"
You can see completed package.json and full repo from this tutorial
https://github.com/Hyra/vue-components-in-express/blob/master/package.json
{
"name": "vue-components-in-express",
"version": "0.0.1",
"private": false,
"description": "Sample code to support blog post 'Using Vue Components in your Express app' at https://mindthecode.com/using-vue-components-in-your-express-app/",
"author": "Stef van den Ham <stef#mindthecode.com>",
"scripts": {
"start": "node ./bin/www",
"dev": "watchify -vd -p browserify-hmr -t vueify -e public/javascripts/main.js -o public/javascripts/bundle.js & node ./bin/www"
},
"dependencies": {
"body-parser": "~1.15.2",
"browserify-hmr": "^0.3.5",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.14.0",
"morgan": "~1.7.0",
"node-sass": "^4.5.3",
"pug": "~2.0.0-beta6",
"serve-favicon": "~2.3.0",
"vue": "^2.5.0",
"vueify": "^9.4.1",
"watchify": "^3.9.0"
}
}

Error R10 (Boot timeout) on heroku, works in <5 sec using npm start and heroku locally

I'm trying to run a node.js app on heroku, it runs fine using npm start and using heroku locally, but does not run when hosted on heroku. I have looked through all the solutions i could find, the remote mongodb database works fine when run using npm start, my port is set up correctly, have restarted heroku and dynamos a bunch of times, and I have a procfile with the following:
web node index.js
The following is the console messages I get:
Starting process with command `node index.js`
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
Application ready to serve requests.
Environment: production
app[web.1]: (node:4) DeprecationWarning: `open()` is deprecated in
mongoose >= 4.11.0,
use `openUri()` instead, or set the `useMongoClient` option if using
`connect()`
or `createConnection()`. See
http://mongoosejs.com/docs/connections.html#use-mongo-client
Db.prototype.authenticate method will no longer be available in the
next major
release 3.x as MongoDB 3.6 will only allow auth against users in the
admin db
and will no longer allow multiple credentials on a socket. Please
authenticate using MongoClient.connect with auth credentials.
DB Connection Open...
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within
60 seconds of launch
Stopping process with SIGKILL
Process exited with status 137
This is my package.json:
{
"name": "shop",
"version": "0.1.0",
"description": "eCommerce Site",
"author": "Slav Bugryn",
"main": "index.js",
"scripts": {
"test": "grunt test",
"build": "grunt build",
"all": "npm run build && npm run test",
"start": "node server.js"
},
"dependencies": {
"connect-flash": "^0.1.1",
"construx": "^1.0.0",
"construx-copier": "^1.0.0",
"construx-dustjs": "^1.1.0",
"construx-less": "^1.0.0",
"dust-makara-helpers": "^4.2.0",
"dustjs-helpers": "^1.7.3",
"eslint": "^4.12.1",
"express": "^4.12.2",
"express-messages": "^1.0.1",
"kraken-js": "^2.0.0",
"makara": "^2.0.3",
"mongodb": "^2.2.33",
"mongoose": "^4.13.6",
"requirejs": "^2.3.5"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"grunt-config-dir": "^0.3.2",
"grunt-contrib-clean": "^1.1.0",
"grunt-contrib-less": "^1.4.1",
"grunt-contrib-requirejs": "^1.0.0",
"grunt-copy-to": "0.0.12",
"grunt-dustjs": "^1.4.0",
"grunt-eslint": "^20.1.0",
"grunt-makara-amdify": "^1.0.1",
"grunt-mocha-cli": "^3.0.0",
"mocha": "^4.0.1",
"supertest": "^3.0.0"
},
"directories": {
"lib": "lib",
"test": "test"
},
"keywords": [],
"license": "ISC"
}
Any advice would be greatly appreciated, thanks in advance.
Figured it out! I sent the Procfile to the wrong place (had to go to server.js, which i found out by looking in package.json and finds start under scripts), after fixing that I got another error (same as here, where i also got the fix: Got a internal server error after I deploy my node js project to the host) which i fixed by running grunt build (had to use --force too).

Resources