Nodemon and Nodejs

Asked

Viewed 477 times

0

I am learning nodejs and would like to know how to add nodemon so that every time I save the project the same update my web page.

I installed nodemon globally and put it in the package.json call

{
  "name": "meuprojeto",
  "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",
    "ejs": "~2.5.7",
    "express": "~4.15.5",
    "morgan": "~1.9.0",
    "serve-favicon": "~2.4.5"
  }
}

Only when saving, my web page does not update automatically.

I also tried to run the project directly with nodemon, entering the folder and typing nodemon.

How do I set it up correctly?

2 answers

1

0

You install the nodemon with

npm install --save-dev nodemon

or with yarn

yarn add -D nodemon

In your package.json, you let

"scripts": {
  "dev": "nodemon teudiretorio/server.js"
},

To rotate, just type npm run dev or yarn dev. Avoids using start with nodemon because when you make some build and play on an external server, such as heroku, for example, this server will use start to start your application. Like nodemon was installed in development mode only at the time of startar your application will generate error because this dependency will not be installed in the application. Basically, your package.json will look like this:

"scripts": {
  "dev": "nodemon teudiretorio/server.js",
  "start": "node teudiretorio/server.js"
},

Browser other questions tagged

You are not signed in. Login or sign up in order to post.