node start with nodemon - node.js

Learning node with express, downloaded and currently studing a structure template, but forget how to start the nodemon so that any update is automatically applied. I was given the command from where I got the template but lost the locaion and after readying up on some of the commands of npm, node,... I could not come up with how2. Thx
Currnet command to run the app is:
npm start
//package.json
{
"name": "eautoshop",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"devstart": "nodemon ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"express": "~4.16.1",
"express-validator": "^6.2.0",
"http-errors": "~1.6.3",
"morgan": "~1.9.1",
"mysql": "^2.17.1",
"pug": "^2.0.4"
},
"devDependencies": {
"nodemon": "^1.19.4"
}
}
nodemon app
gives the error:
'nodemon' is not recognized as an internal or external command,
operable program or batch file.

You can just point the nodemon executable...
node node_modules/nodemon/bin/nodemon.js bin/www

Related

How do I safely run 'npm audit fix --force'?

I want to run the npm command 'npm audit fix --force', because I already ran 'npm audit fix' and there are still vulnerabilities, is there a way I can somehow fix all the vulnerabilities without breaking my program, I tried running the command in a cloned file to see what damage it would cause, and you guessed it, it broke.
Is there a way I can somehow modify the package.json and package-lock.json to fix this?
Here is my package (making a login and registration system via mongodb)
{
"name": "passport-local-register-login",
"version": "2.0.0",
"description": "Node.js authentication with Passport",
"main": "app.js",
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"connect-flash": "^0.1.1",
"ejs": "^2.6.1",
"express": "^4.16.4",
"express-ejs-layouts": "^2.5.0",
"express-session": "^1.15.6",
"mongoose": "^5.7.5",
"passport": "^0.4.0",
"passport-local": "^1.0.0"
},
"devDependencies": {
"nodemon": "^1.18.9"
}
}

Heroku - SSL off error - after previously working perfectly

After having everything working on my Heroku app for months, I started getting this error yesterday:
no pg_hba.conf entry for host "x.x.x.x", user "xxxxx", database "xxxxz", SSL off"
I've only been working on the client side and haven't changed anything on the server, so I don't know what could be going on.
server package.json
{
"name": "spiral-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha --require test/setup.js",
"dev": "nodemon src/server.js",
"start": "node src/server.js",
"migrate": "postgrator --config postgrator-config.js",
"migrate:test": "env NODE_ENV=test npm run migrate",
"migrate:production": "env SSL=true DATABASE_URL=$(heroku config:get DATABASE_URL) npm run migrate",
"predeploy": "npm audit",
"deploy": "git push heroku master",
"postdeploy": "npm run migrate:production"
},
"keywords": [],
"engines": {
"node": "12.14.1"
},
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"helmet": "^4.1.0",
"jsonwebtoken": "^8.5.1",
"knex": "^0.21.5",
"morgan": "^1.10.0",
"pg": "^8.3.3",
"postgrator": "^4.0.1",
"postgrator-cli": "^3.2.0",
"xss": "^1.0.8"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^8.1.1",
"nodemon": "^2.0.4",
"supertest": "^4.0.2"
}
}
I'm not sure how to start debugging, when I already had it working perfectly.
The only change I might have made was to the GitHub repo name (I changed a few repo names, and not sure if I changed this one or not)
All my other work has been on the client which is a React app hosted on Vercel.
I get the pg error when I query from localhost, Vercel, or Postman.
Any suggestions?
Try the following.
Add a new PGSSLMODE env variable with require as value under your app settings in Heroku.
Then restart your dyno...
heroku ps:restart

Cannot find module 'Express'; already installed locally and globally

I have a project that is using express for the backend API. The project is working on my local machine but when I try to deploy it on a linux VM I get the error "Cannot find module 'Express'".
The steps I took to produce this error were cloning and cding into the repo, and running npm install. express is listed as a dependency in the package.json file. I tried explicitly running npm install express and npm install -g express and both said that they added and/or updated packages and did not return any errors. I also looked in the node_modules folder and there is an express folder there as well.
My package.json:
{
"name": "user-backend",
"version": "1.0.0",
"private": true,
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev-start": "nodemon server.js",
"nvm-start": "nvm use 8.11.3",
"postnvm-start": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.18.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"cors": "^2.8.4",
"dotenv": "^6.0.0",
"express": "^4.16.3",
"faker": "^4.1.0",
"helmet": "^3.12.1",
"jsonwebtoken": "^8.3.0",
"mongoose": "^5.2.2",
"morgan": "^1.9.0",
"request": "^2.88.0",
"slugify": "^1.3.1",
"validator": "^10.4.0"
},
"devDependencies": {
"nodemon": "^1.18.1"
}
}
Any help would be greatly appreciated. Thank you
This ended up being a simple syntax error in my import ("Express" vs "express")

nodemon not refreshing when using typescript

I'm working on an app with NodeJs, express, typescript and nodemon.
But the page is not refreshed when I changed some code in the ts files.
How can I do to compile the ts file in js and refresh the browser with nodemon (or other tool)?
package.json
{
"name": "myapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.17.2",
"debug": "^2.6.8",
"dotenv": "^2.0.0",
"express": "^4.15.3",
"iconv-lite": "^0.4.17",
"inversify": "^4.11.1",
"jsonwebtoken": "^7.4.1",
"mongoose": "^5.0.10",
"morgan": "^1.8.2",
"passport": "^0.3.2",
"passport-jwt": "^2.2.1",
"rxjs": "^5.4.2",
"typescript": "^2.7.2",
"winston": "^2.3.1"
},
"devDependencies": {
"#types/chai": "^4.0.0",
"#types/debug": "0.0.29",
"#types/dotenv": "^2.0.20",
"#types/express": "^4.0.35",
"#types/mocha": "^2.2.41",
"#types/mongoose": "^4.7.15",
"#types/morgan": "^1.7.32",
"#types/node": "^6.0.77",
"#types/passport": "^0.3.3",
"#types/passport-jwt": "^2.0.20",
"chai": "^4.0.2",
"chai-http": "^3.0.0",
"gulp": "^3.9.1",
"gulp-clean": "^0.3.2",
"gulp-typescript": "^3.1.7",
"gulp-yaml": "^1.0.1",
"mocha": "^3.4.2",
"mocha-typescript": "^1.1.4"
},
"scripts": {
"start": "gulp build && nodemon dist/index.js",
"build": "gulp build",
"test": "gulp build && mocha -t 30000 dist/**/*.test.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/devslaw/TypeScript-Node.js-REST-example.git"
},
"keywords": [],
"author": "Arthur Arakelyan <arthur#devslaw.com>",
"license": "ISC",
"homepage": "https://github.com/devslaw/TypeScript-Node.js-REST-example#readme"
}
So know, anytime i make a change, I need to stop the server and run npm start again
The problem lies in the fact that your start script is watching dist/index.js. This folder only changes when the code gets recompiled into plain JavaScript. So you will need to watch the TypeScript files instead. The great thing is that you can change nodemon's default behavior. You will need to add ts-node to your package.json as well.
Try setting the script to something like the following:
nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts
You will then want to set up a nodemon.json file with the following also:
{
"watch": ["src"],
"ext": "ts",
"exec": "ts-node ./src/index.ts"
}

My express app is not start,how can I do with it?

I created a Express application by Express test and then I npm installthe package in test directory,but when I use npm start,my project can not run in my browser.Just like that:
This situation kept for a long time and I don't know how to deal with it.
My package.json is:
{
"name": "test",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.17.1",
"cookie-parser": "~1.4.3",
"debug": "~2.6.3",
"express": "~4.15.2",
"jade": "~1.11.0",
"morgan": "~1.8.1",
"serve-favicon": "~2.4.2"
}
}
Can anyone help me ?

Resources