38

in my package.json I am using

"scripts": {
  "start": "node app.js"
},

but if I use nodemon replace with node app.js like

"scripts": {
  "start": "nodemon app.js"
},

then what will happen? Because when I got any error at server side, other API also close working. So I think it happen because I use node app.js if I use nodemon app.js than server will restart or not.

sonali
  • 762
  • 10
  • 23
Alex
  • 818
  • 1
  • 8
  • 17

8 Answers8

39

When you develop a node app and you make some changes, to see them in effect you have to restart the server.

When you launch your node.js application with Nodemon it will monitor for any changes and automatically restart the server, improving your productivity.

Simone Poggi
  • 1,448
  • 2
  • 15
  • 34
  • 2
    This is another question :) Have you installed it with the g flag? `npm install -g nodemon` you got any error during the installation? – Simone Poggi Aug 20 '16 at 08:29
  • ya but your answer also not meet my quetion i ask it for package.json and you tell me for bash command . – Alex Aug 20 '16 at 08:31
  • to need to install it globally with `-g` flag as @Motocarota mentioned – candidJ Aug 20 '16 at 08:31
  • i got warning like npm WARN optional dep failed, continuing fsevents@1.0.14 – Alex Aug 20 '16 at 08:32
  • Well it'a warning about an optional dep so it wouldn't be a big issue, have you tried to run `nodemon -v` after the install? If the command is found you can now run your package.json script – Simone Poggi Aug 20 '16 at 08:34
  • if i run `npm nodemon -v` , i got version number – Alex Aug 20 '16 at 08:42
  • Seems like your nodemon install does not work; you can try with an alternative tool http://stackoverflow.com/questions/12559176/is-there-anything-like-nodemon-that-will-restart-a-node-app-when-ejs-file-chang – Simone Poggi Aug 20 '16 at 09:11
12

Nodemon is a utility that will monitor for any changes in your source and automatically restart your server. Perfect for development. Install it using npm.

npm install -g nodemon

How to use nodemon?

nodemon "filename" ignore the quotation and place name of the server file.

Nodemon:

  • monitors for any changes in your Node.js application
  • automatically restarts the server,
  • saving time and tedious work.
  • it's one way to make your development efficient with Opn:

Opn is a dependency that opens web browser links, files, and executables. We will be using Opn to automatically open a web browser to our local host every time our server restarts.Install with npm npm install opn.

How to use node?

node "filename" ignore the quotation and place the filename (ex app.js ,server.js)

node:

  • no automatic restart the server every time you do the tedious work
  • no monitors for any change
juanlumn
  • 6,155
  • 2
  • 30
  • 39
yosef girma
  • 181
  • 2
  • 2
6

nodemon is like a live-server for your node application. any changes made in your node application will get reflected as server will restart again. as stated here :

nodemon will watch the files in the directory in which nodemon was started, and if any files change, nodemon will automatically restart your node application.

candidJ
  • 4,289
  • 1
  • 22
  • 32
  • i can not use nodemon it give me error after install nodemon and use it bash: nodemon: command not found – Alex Aug 20 '16 at 08:29
4

nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.

To use nodemon, replace the word node on the command line when executing your script.

In terminal,instead of typing node app.js,you can type: npm start

In package.json file,you can change it to:

"scripts": {
    "start": "nodemon app.js"
   
  },

In short,it is like a live server for node js, like we have in HTML & CSS.

Milan Kumar Bura
  • 350
  • 5
  • 11
2

When you are using node you have to restart on your own to see the changes you made But nodemon watches the particular path for any changes.If you make any changes in your file, nodemon will restart it for you.

VB11
  • 27
  • 1
  • 5
1

when we install node, we will get automatically node and npm global variable.

for using nodemon you need to install it

npm install -g nodemon

we can access files with node as well but each time when we do changes we need to stop server and restart it.

node "filename" // provide filename

but if we accessing file with nodemon you no need to stop server and restart it only one line of command will save restart server time

nodemon "filename" // provide filename

this one line helps you saving lot of development time and test your sample javascript code

MSA
  • 249
  • 5
  • 10
1

Nodemon stands for Node Monitor. When you run a server using the command node index.js, after every change in your code you have to again run the node index.js command and reload the page to see the changes. Nodemon solves this problem for you. It auto-updates the server for you.

1

Just wanted to add that if you're using Node v18.11.0+ you no longer need to install nodemon as node added --watch flag which watches files for changes and reloads for you like nodemon.

"scripts": {
  "start": "node --watch app.js"
},
amerikan
  • 29
  • 4