4

I've just setup MEAN stack on my DigitalOcean server. I got the test app to run fine, but now when I open command line from DigitalOcean it just shows info: GET /modules/etc... and the part where I type is blank. How do I stop the server and get it back to where it was originally so I can access folders etc.?

Simply doing CTRL+C does not stop the server from running, which is what I need to do.

Alanay
  • 425
  • 2
  • 5
  • 9

7 Answers7

12

At first: CTRL+Z will terminate the execution. Later, in order to terminate the PID(processID), follow the following.

The generalised approach for kill any processId including localserver:

Reference: https://stackoverflow.com/a/57536823/8119511

For this case:

$:lsof -i tcp:<PORT>

It will bring you out with the PID(processId) associated with port:

$:kill -9 <process-id>

And again, you can runserver.

Ank_247shbm
  • 512
  • 7
  • 17
  • What a load of extra maintenance. Why doesn't node have a stop/start script live every other http server is beyond my imagination. So much for beating concurrency – Vijay Kumar Kanta Nov 15 '19 at 10:16
4

You can stop the server by killing the process. In Windows, run CMD and type taskkill /F /IM node.exe This will kill(stop) all Node.js processes. And then you can restart it.

Jin Lee
  • 3,194
  • 12
  • 46
  • 86
1

To programmatically kill a program (e.g. node's http-server) via the command-line or a BASH script.

[victoria@victoria ~]$ pgrep -a node     ## pgrep --help
  1315229 node /usr/bin/http-server -p 8080 /mnt/Vancouver/

[victoria@victoria ~]$ pgrep -l -f node
  1315229 node

[victoria@victoria ~]$ pgrep -l -f http-server
  1315229 node

[victoria@victoria ~]$ pgrep -f http-server
  1336598

[victoria@victoria ~]$ a=$(pgrep -f node)    ## or: a=$(pgrep -f http-server)

[victoria@victoria ~]$ echo $a
  1315229

[victoria@victoria ~]$ kill -9 $a

[victoria@victoria ~]$ pgrep -a node
[victoria@victoria ~]$

## one-liner:  a=$(pgrep -f node); kill -9 $a
Victoria Stuart
  • 4,610
  • 2
  • 44
  • 37
0

what are you using? did you try control+c in your command prompt or terminal?

Edit: go to your config.js file or server file you are using to specify what port you want to use. if you are testing on localhost type in your browswer localhost:port

var http = require('http'); 
var url = require('url'); 
http.createServer(function (req, res) { 
 console.log("Request: " + req.method + " to " + req.url); 
 res.writeHead(200, "OK"); 
 res.write("<h1>Hello</h1>Node.js is working"); 
 res.end(); 
}).listen(8080); 
console.log("Ready on port 8080");
0

Just open the task manager. search for the the node.js process in processes. then end the process and try it will work.

  • Opening task manager from command line isn't a solution actually if he is on linux system and accessed it via SSH – critrange Jul 26 '20 at 15:28
0

Well, you can simply stop it on "Output" console: Just right click and select the "Stop code run" option.

enter image description here

Vega
  • 27,856
  • 27
  • 95
  • 103
0

CTRL+C you should use only when you are using OS
windows & in the code using :

app.close();

if you have like this

let app = require('express'); // or any frameworks