bruceparker
bruceparker

Reputation: 1255

nodemon not working properly

I am running my nodejs app by npm start

I just installed nodemon by sudo npm install -g nodemon so that i can get my server restarted when i save changes to files.

But when i try to start the server, something like this

nodemon ./app.js localhost 3000 or nodemon start localhost 3000

I get this as output

LM-SJC-00871929:webapp gdeep$ nodemon ./app.js localhost 3000
28 May 23:34:30 - [nodemon] v1.1.1
28 May 23:34:30 - [nodemon] to restart at any time, enter `rs`
28 May 23:34:30 - [nodemon] watching: *.*
28 May 23:34:30 - [nodemon] starting `node ./app.js localhost 3000`

but when i go to my webpage, i get

Oops! Google Chrome could not connect to localhost:3000. What am i doing wrong?

App.js here http://collabedit.com/t35dy

Upvotes: 37

Views: 145124

Answers (20)

Stanley Ulili
Stanley Ulili

Reputation: 1354

Update as of 2024

If you have Node.js 18 or higher installed, you no longer need to use Nodemon. Instead, you can pass the --watch flag(experimental) and Node will automatically restart the server for you:

node --watch index.js

The --watch option is now stable with the release of Node.js 22.

Upvotes: 0

Yue Yin
Yue Yin

Reputation: 166

If you are using express4, the easiest way is to navigate to package.json and change

"scripts": {
    "start": "node ./bin/www"
}

to

"scripts": {
    "start": "nodemon ./bin/www"
}

Upvotes: 2

AMAY SANDANSHIV
AMAY SANDANSHIV

Reputation: 1

Try this command on terminal if you are using Nodejs & TypeScript

npm i --dev nodemon ts-node

Upvotes: 0

ankit das
ankit das

Reputation: 1

You can directly use the command nodemon start to start your server.

Upvotes: 0

Try this:

First install nodemon by npm install nodemon or any command from the official website (https://www.npmjs.com/package/nodemon) Then start your nodemon by npx nodemon filename.js or if you have your package.json with you and the entry point is the file you would like to open then you can also go with the command npx nodemon Check this once

Hope it works!!

Happy Coding 😀

Upvotes: 1

Wasif Khan
Wasif Khan

Reputation: 1

First of all, uninstall nodemon:

npm uninstall nodemon

After uninstalling the nodemon then install nodemon globally using:

npm i -g nodemon

It will install nodemon globally then run the following command:

nodemon index.js or app.js

Upvotes: -2

hilmidemirtas
hilmidemirtas

Reputation: 40

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

check it, if it's true or not

Upvotes: 0

ujjwal jain
ujjwal jain

Reputation: 71

  1. npm i nodemon
  2. Edit your Package.json file:- set start to nodemon:
"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon server.js"
}
  1. Run npm start to try the server

Upvotes: 6

Masih Jahangiri
Masih Jahangiri

Reputation: 10897

Use single quotation for multi-value args like `--exec'.

e.g. I changed "nodemon --exec yarn build-langs" to "nodemon --exec 'yarn build-langs'" and worked.

Upvotes: 0

Rituraj Kulshresth
Rituraj Kulshresth

Reputation: 1

Certain child processes related to your parent process may not be closed. Try to kill all the child processes.

Ref: https://github.com/remy/pstree

Upvotes: 0

Skoua
Skoua

Reputation: 3603

Here's what I did to make nodemon update correctly:

nodemon index.js -L

The -L flag stands for legacyWatch, here's an explanation from the official doc:

In some networked environments (such as a container running nodemon reading across a mounted drive), you will need to use the legacyWatch: true which enables Chokidar's polling.

https://www.npmjs.com/package/nodemon#application-isnt-restarting

Upvotes: 27

Sheshadri H
Sheshadri H

Reputation: 1

try

npm install --save-dev nodemon

and then in package.json file keep like this

"scripts": {
    "start": "nodemon",
    "test": "echo \"Error: no test specified\" && exit 1"
  },

instead of npx nodemon, which takes more time

Upvotes: -1

Garth
Garth

Reputation: 3308

In my case, I had to install nodemon globally. Use this command to do so..

npm install -g nodemon

If you're using Linux you may need to prefix the command with the sudo keyword for administration access..

sudo npm install -g nodemon

Upvotes: 10

eskander barhi
eskander barhi

Reputation: 11

thanks you need to type this after to enter in the folder application with

cd your_project_folder

sudo nodemon bin/www

Upvotes: 0

BHUVNESH KUMAR
BHUVNESH KUMAR

Reputation: 401

Add following code in your code

  1. app.js

    app.listen(3000, function(){
        console.log("info",'Server is running at port : ' + 3000);
    });
    
  2. package.json

    nodemon app.js 
    

Then run npm start from the command line.

Upvotes: 5

czerasz
czerasz

Reputation: 14250

You might also run into the issue of having an empty .nodemonignore.

Upvotes: -1

Dinesh
Dinesh

Reputation: 548

For Express.js 4,
use nodemon
or
nodemon bin/www

Upvotes: 5

Jackal
Jackal

Reputation: 2692

For Express 4; Just run

nodemon

command (with out any args) on the directory; this works for me.

Upvotes: 0

SomeKittens
SomeKittens

Reputation: 39512

You're running express 4, which has the app.listen call in a different file than app.js. The command you're looking for is nodemon bin/www (localhost and 3000 are not needed in this scenario).

In fact, you can even run nodemon with no args, and it'll read what command needs to be run from scripts.start in package.json (which express generates automatically).

Upvotes: 55

user3607134
user3607134

Reputation: 108

try running nodemon ./app.js 3000 or nodemon start 3000

Upvotes: 8

Related Questions