Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node js is still listening to the port after ctrl+z

I am trying to learn some features of node on ubuntu and after I press ctrl+z on my console to stop the server I had (in order to restart server for recognizing my changes on the code), the node still listens to the port (in this case 3000 ).

Then, everytime I have to find the pid by typing

lsof -i tcp:3000

and kill it manually by typing

sudo kill -9 pid_number_I_got

I just wonder why it still listens to it and I want not to have to do this thing everytime. Any help ?


The code

var http = require("http");

var server = http.createServer(function(req,res){
    console.log(req.url , req.method);
    res.end("hello \n");
});

server.listen(3000);

The answer is correct. Type ctrl+c , it works. I was typing ctrl+x instead.

like image 705
FurkanO Avatar asked Dec 13 '15 23:12

FurkanO


1 Answers

Ctrl+Z moves a running application to the background; you can run the fg command to resume it. To stop the server, you should use Ctrl+C.

like image 161
Michelle Tilley Avatar answered Oct 07 '22 04:10

Michelle Tilley