2

I have created a node application and run it in 3000 port. Now I need to stop/start/restart this application by using command prompt. How can I do it.

Rasmikant
  • 541
  • 3
  • 6
  • 11
  • Possible duplicate of [How do I get started with Node.js](http://stackoverflow.com/questions/2353818/how-do-i-get-started-with-node-js) – Tim Ogilvy Mar 16 '16 at 04:26
  • Possibly related: [node.js as a background service](http://stackoverflow.com/questions/4018154/node-js-as-a-background-service) – Jonathan Lonowski Mar 16 '16 at 04:41
  • In general... Start: execute `node entryScript.js` – Stop: [`[Ctrl]+[c]`](http://stackoverflow.com/questions/6108953/how-does-ctrl-c-terminate-a-child-process) – Jonathan Lonowski Mar 16 '16 at 04:42

3 Answers3

5

Start:node app.js

Stop:Ctrl + C

Restart:node app.js

Better option try Nodemon. Nodemon is a utility that will monitor for any changes in your source and automatically restart your server.

  1. Install nodemon globally npm install nodemon -g

  2. Run the server nodemon app.js

Nivesh
  • 2,573
  • 1
  • 20
  • 28
  • yes but in my server multiple node application is running. How I can stop a particular app running on 3000 port – Rasmikant Mar 16 '16 at 06:53
2

Assuming you are using linux If you need to stop some application running on some specific port use this and you know the port but not the process id. find the process id like this

netstat -plten | grep LISTEN | grep 3000

this will output some thing like this

tcp        0      0 :::10060                    :::*                          LISTEN      0          20465      3489/node    

where 3489 is the process id.

then do

kill -9 3489 

to kill the procees

Mustafa Mamun
  • 2,591
  • 2
  • 14
  • 17
1

You can simply press 'Ctrl + C' to stop any process in cmd. Also consider using nodemon , its a fantastic tool which automatically restarts your app whenever you save any new changes to the files.

Ankur Rana
  • 88
  • 9