localhost:3000 is not working in the browser - javascript

Backend: Express server, with npx create-express-api backend
Frontend: Next.js, with npx create-react-app frontend
I have implemented these command in my root folder and trying to run npm start xxx to check if they are still working or not. But they are not working in my http://localhost:3000
Though they are working in this link http://172.27.178.192:3000 (on my network)
This is the image showing the problem
I have changed browsers and still the same problem is appearing. On the browser it says
Unable to connect
Firefox can’t establish a connection to the server at localhost:3000.

netstat -ano | findstr :8080
Then the PID will appear at the right which you can kill with taskkill.
The last number the pid.
then:
taskkill/pid 11704 /F
How to close TCP and UDP ports via windows command line

I think some other application occupied your 3000 port. try find which one is. If you have found then closed and try again.
For instance you want to free the port 3000 Then, follow these commands.
netstat -ano
taskkill /f /im [PID of the port 3000 got from previous command]
How to close TCP and UDP ports via windows command line

in browser history search for localhost:3000 and delete all of them.
make sure you closed all terminalls(check vscode too) and all tabs in your browsers.
in new widnows terminal npx kill-port 3000 do it in WSL2 terminall too.
make sure your firewall is turn of.
restart you computer.

It worked for me
Delete the .next folder ( if your working on nextjs ) and try npm run dev command OR
Move the project to another folder location OR
Take back up of the code and delete the project and then run the same project again
You can try all of the above also

Related

Localhost:3000 is not working properly in windows while creating a reactjs app with CRA

There are few points, for the past few days I am trying to figure out the issue but I am stuck.
I have tried to stop localhost:3000 with
netstat -ano | findstr :3000
taskkill /PID myPIDhere /F
But still, then I am getting-
TCP 0.0.0.0:3000 0.0.0.0:0 LISTENING 5748
and it says - ERROR: The process with PID 5748 could not be terminated.
Reason: There is no running instance of the task.
And still, when I visit localhost:3000 it trying to load again and again.
whenever I try to create a reactjs app with CRA.. the terminal hangs there forever.
same goes for NPM install in a creatjs app.
EDIT 2 : netstat -ano | findstr :3000
tskill typeyourPIDhere
Use tskill in windows cmd vs taskkill on git-bash
EDIT: Try wmic process where name="[process name]" call terminate / delete
Off the top of my head, try changing CRA port to something else?
https://scriptverse.academy/tutorials/reactjs-change-port-number.html
Try one of these methods, and see if they help you at least run CRA.

EADDRINUSE error when creating an express server with next.js [duplicate]

I have a simple server running in node.js using connect:
var server = require('connect').createServer();
//actions...
server.listen(3000);
In my code I have actual handlers, but thats the basic idea. The problem I keep getting is
EADDRINUSE, Address already in use
I receive this error when running my application again after it previously crashed or errors. Since I am not opening a new instance of terminal I close out the process with ctr + z.
I am fairly certain all I have to do is close out the server or connection. I tried calling server.close() in process.on('exit', ...); with no luck.
First, you would want to know which process is using port 3000
sudo lsof -i :3000
this will list all PID listening on this port, once you have the PID you can terminate it with the following:
kill -9 <PID>
where you replace <PID> by the process ID, or the list of process IDs, the previous command output.
You can also go the command line route:
ps aux | grep node
to get the process ids.
Then:
kill -9 PID
Doing the -9 on kill sends a SIGKILL (instead of a SIGTERM).
SIGTERM has been ignored by node for me sometimes.
I hit this on my laptop running win8. this worked.
Run cmd.exe as 'Administrator':
C:\Windows\System32>taskkill /F /IM node.exe
SUCCESS: The process "node.exe" with PID 11008 has been terminated.
process.on('exit', ..) isn't called if the process crashes or is killed. It is only called when the event loop ends, and since server.close() sort of ends the event loop (it still has to wait for currently running stacks here and there) it makes no sense to put that inside the exit event...
On crash, do process.on('uncaughtException', ..) and on kill do process.on('SIGTERM', ..)
That being said, SIGTERM (default kill signal) lets the app clean up, while SIGKILL (immediate termination) won't let the app do anything.
Check the PID i.e. id of process running on port 3000 with below command :
lsof -i tcp:3000
It would output something like following:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 5805 xyz 12u IPv6 63135 0t0 TCP *:3000 (LISTEN)
Now kill the process using :
kill -9 5805
For macOS Monterey(12.0):
Apple introduced some changes for AirPlay on macOS Monterey. Now, it uses 5000 and 7000 ports. If you are using these ports in your project, you need to disable this feature.
System Preferences > Sharing > untick AirPlay Receiver
For macOS Ventura(13.0) and above users:
System Settings > General > disable AirPlay Receiver
I found this solution, try it
Give permission use sudo
sudo pkill node
I usually use
npx kill-port 3000
or on my mac.
killall node
Rewriting #Gerard 's comment in my answer:
Try pkill nodejs or pkill node if on UNIX-like OS.
This will kill the process running the node server running on any port.
Worked for me.
Linux
Run ps and determine the PID of your node process.
Then, run sudo kill PID
Windows
Use tasklist to display the list of running processes:
tasklist /O
Then, kill the node process like so (using the PID obtained from the tasklist command):
taskkill /pid PID
Here is a one liner (replace 3000 with a port or a config variable):
kill $(lsof -t -i:3000)
For windows open Task Manager and find node.exe processes. Kill all of them with End Task.
I was getting this error once and took many of the approaches here.
My issues was that I had two app.listen(3000); calls in the same app.js script. The first app.listen() succeeded where the second threw the error.
Another useful command I came across that helped me debug was sudo fuser -k 3000/tcp which will kill any rogue processes you might have started (some processes may restart, e.g. if run with forever.js, but it was useful for me).
For Visual Studio Noobs like me
You may be running the process in other terminals!
After closing the terminal in Visual Studio, the terminal just disappears.
I manually created a new one thinking that the previous one was destroyed. In reality, every time I was clicking on New Terminal I was actually creating a new one on top of the previous ones.
So I located the first terminal and... Voila, I was running the server there.
Windows by Cmd
1/2. search => write cmd => open node.js command prompt
2/2. Run windows command: taskkill
Ends one or more tasks or processes.
taskkill /f /im node.exe
/f - force ended
/im - Specifies the image name of the process to be terminated.
node.exe - executable file
Windows - Mannualy by Task Manager
This command is the same as going to Task Manager under the details tab & select node tasks (Tidy in my opinion).
And end task
Visual studio
Sometimes there is more than one terminal/task (client/server and so on).
Select and close by ctrl + c.
You may run into scenarios where even killing the thread or process won't actually terminate the app (this happens for me on Linux and Windows every once in a while). Sometimes you might already have an instance running that you didn't close.
As a result of those kinds of circumstances, I prefer to add to my package.json:
"scripts": {
"stop-win": "Taskkill /IM node.exe /F",
"stop-linux": "killall node"
},
I can then call them using:
npm run stop-win
npm run stop-Linux
You can get fancier and make those BIN commands with an argument flag if you want. You can also add those as commands to be executed within a try-catch clause.
FYI, you can kill the process in one command sudo fuser -k 3000/tcp. This can be done for all other ports like 8000, 8080 or 9000 which are commonly used for development.
ps aux | grep node
kill -9 [PID] (provided by above command)
Description:
ps will give the process status, aux provide the list of a: all users processes, u: user own processes, x: all other processes not attached to terminal.
pipe symbol: | will pass the result of ps aux to manipulate further.
grep will search the string provided(node in our case) from the list provided by ps aux.
First find out what is running using:
sudo lsof -nP -i4TCP:3000 | grep LISTEN
You will get something like:
php-fpm 110 root 6u IPv4 0x110e2ba1cc64b26d 0t0 TCP 127.0.0.1:3000 (LISTEN)
php-fpm 274 _www 0u IPv4 0x110e2ba1cc64b26d 0t0 TCP 127.0.0.1:3000 (LISTEN)
php-fpm 275 _www 0u IPv4 0x110e2ba1cc64b26d 0t0 TCP 127.0.0.1:3000 (LISTEN)
Then you can kill the process as followed:
sudo kill 110
Then you will be able to run without getting the listen EADDRINUSE :::3000 errors
Really simply for all OS's ..
npx kill-port 3000
Although your problem is as mentioned above you need to catch the different ways node can exit for example
process.on('uncaughtException', (err, origin) => {
console.log(err);
});
// insert other handlers.
bash$ sudo netstat -ltnp | grep -w ':3000'
- tcp6 0 0 :::4000 :::* LISTEN 31157/node
bash$ kill 31157
PowerShell users:
Taskkill /IM node.exe /F
UI solution For Windows users: I found that the top answers did not work for me, they seemed to be commands for Mac or Linux users. I found a simple solution that didn't require any commands to remember: open Task Manager (ctrl+shift+esc). Look at background processes running. Find anything Node.js and end the task.
After I did this the issue went away for me. As stated in other answers it's background processes that are still running because an error was previously encountered and the regular exit/clean up functions didn't get called, so one way to kill them is to find the process in Task Manager and kill it there. If you ran the process from a terminal/powerShell you can usually use ctrl+c to kill it.
Task Manager (ctrl+alt+del) ->
Processes tab ->
select the "node.exe" process and hit "End Process"
Just in case check if you have added this line multiple times by mistake
app.listen(3000, function() {
console.log('listening on 3000')
});
The above code is for express but just check if you are trying to use the same port twice in your code.
In windows users: open task manager and end task the nodejs.exe file, It works fine.
On Windows, I was getting the following error:
EADDRINUSE: address already in use :::8081.
Followed these steps:
Opened CMD as Admin
Ran the folowing
command netstat -ano|findstr "PID :8081"
got the following processes:
killed it via:
taskkill /pid 43144 /f
On MAC you can do like this:
raghavkhunger#MacBook-Air ~ % lsof -i tcp:8081
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 23722 username 24u IPv6 0xeed16d7ccfdd347 0t0 TCP *:sunproxyadmin (LISTEN)
username#MacBook-Air ~ % kill -9 23722
With due respect to all the answers in the form, I would like to add a point.
I found that when I terminate a node app on error using Ctrl + Z, the very next time when I try to open it got the same error EADDRINUSE.
When I use Ctrl + C to terminate a node app, the next time I opened it, it did without a hitch.
Changing the port number to something other than the one in error solved the issue.
using netstat to get all node processes with the port they are using and then kill the only one you want by PID
netstat -lntp | grep node
you will get all node processes
tcp6 0 0 :::5744 :::* LISTEN 3864/node
and then when you get the PID (3864) just kill the processes by PID
kill -HUP PID
You may use hot-node to prevent your server from crashing/ run-time-errors. Hot-node automatically restarts the nodejs application for you whenever there is a change in the node program[source] / process[running node program].
Install hot-node using npm using the global option:
npm install -g hotnode

ReactNative port 8081 issue : 403 Forbidden

While developing using ReactNative on Windows, I am getting below 403 error. This is because port 8081 which ReactNative uses by default is being used by another program. In my case it was McAfee (Thanks McAfee for making this harder).
Command to run the project : react-native run-android
I searched around a lot and finally figured out how to run this project on a different port. If you have any Antivirus software installed then it may help if you disable the firewall while developing or allow connections manually through settings.
Start ReactNative on a different port
react-native start --port 9080
This will open a new command prompt and start the metro bundler on port 9080 (you can use any other port you want). Wait for the dependency graph to be fully loaded.
Now in a different command prompt (project directory) use the below command to build and install the app on device
react-native run-android
Now once the app is loaded on device you will see the 403 error along with the red screen. To make the device communicate on a different port use below command.
adb reverse tcp:8081 tcp:9080
or if you have multiple device connected then provide the device id (e.g. FA6AA0301277)
adb -s FA6AA0301277 reverse tcp:8081 tcp:9080
To know the list of devices connected use below command
adb devices
That's it, now you should be able to see the index page :)
Happy Coding :)

Node JS ctrl + C doesn't stop server (after starting server with "npm start")

When I start my server with node app.js in the command line (using Git Bash), I can stop it using ctrl + C.
In my package.json file i got this start-script that allows me to use the command npm start to start the server:
"scripts": {
"start": "node app"
},
When I do this, the server starts as normal:
$ npm start
> nodekb#1.0.0 start C:\Projects\nodekb
> node app.js
Server started on port 3000...
But when i ctrl + C now, the server does not get stopped (the node process still remains in task manager). This means that I get an error when I try to do npm start again, because port 3000 is still being used.
I'm following a tutorial on youtube (video with timestamp), and when this guy ctrl + C and then runs npm start again, it works as normal.
Any ideas why my server process is not stopped when I use ctrl + C?
My app.js file if needed:
var express = require("express");
var path = require("path");
//Init app
var app = express();
//Load View Engine
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "pug");
//Home Route
app.get("/", function(req, res) {
res.render("index", {
title: "Hello"
});
});
//Add route
app.get("/articles/add", function (req, res) {
res.render("add_article", {
title: "Add Article"
});
});
//Start server
app.listen(3000, function() {
console.log("Server started on port 3000...");
});
Thanks!
Ctrl + C does not kill the server. The resolution to the issue was using following code snippet in server.js:
process.on('SIGINT', function() {
console.log( "\nGracefully shutting down from SIGINT (Ctrl-C)" );
// some other closing procedures go here
process.exit(0);
});
This worked for me.
You can also check for other solutions mentioned at Graceful shutdown in NodeJS
I tried it on normal windows cmd, and it worked as it should there. Looks like it's a problem with git bash.
I encountered this problem in MSYS2 proper, even in latest build (x64 2018-05-31).
Luckily, Git for Windows maintain a customized MSYS2 runtime. They have patches that have not been sent upstream, including a patch that fixes emulation of SIGINT, SIGTERM and SIGKILL.
Discussion: https://github.com/nodejs/node/issues/16103
I was able to make my "MSYS2 proper" platform use Git for Windows' MSYS2 runtime, by following these instructions.
Repeated here for posterity:
Install inside MSYS2 proper
This guide assumes that you want the 64-bit version of Git for Windows.
Git for Windows being based on MSYS2, it's possible to install the git package into an existing MSYS2 installation. That means that if you are already using MSYS2 on your computer, you can use Git for Windows without running the full installer or using the portable version.
Note however that there are some caveats for going this way. Git for Windows created some patches for msys2-runtime that have not been sent upstream. (This had been planned, but it was determined in issue #284 that it would probably not be happening.) This means that you have to install Git for Windows customized msys2-runtime to have a fully working git inside MSYS2.
Here the steps to take:
Open an MSYS2 terminal.
Edit /etc/pacman.conf and just before [mingw32] (line #71 on my machine), add the git-for-windows packages repository:
[git-for-windows]
Server = https://wingit.blob.core.windows.net/x86-64
and optionally also the MINGW-only repository for the opposite architecture (i.e. MINGW32 for 64-bit SDK):
[git-for-windows-mingw32]
Server = https://wingit.blob.core.windows.net/i686
Authorize signing key (this step may have to be repeated occasionally until https://github.com/msys2/msys2/issues/62 is fixed)
curl -L https://raw.githubusercontent.com/git-for-windows/build-extra/master/git-for-windows-keyring/git-for-windows.gpg |
pacman-key --add - &&
pacman-key --lsign-key 1A9F3986
Then synchronize new repository
pacboy update
This updates msys2-runtime and therefore will ask you to close the window (not just exit the pacman process). Don't panic, simply close all currently open MSYS2 shells and MSYS2 programs. Once all are closed, start a new terminal again.
Then synchronize again (updating the non-core part of the packages):
pacboy update
And finally install the Git/cURL packages:
pacboy sync git:x git-doc-html:x git-doc-man:x git-extra: curl:x
Finally, check that everything went well by doing git --version in a MINGW64 shell and it should output something like git version 2.14.1.windows.1 (or newer).
Note: I found that the git-extra package installed by step 7 was quite intrusive (it adds a message "Welcome to the Git for Windows SDK!" to every terminal you open), so I removed it with pacman -R git-extra.
Note 2: I also found that Git for Windows' MSYS2 runtime opens in a different home directory than did MSYS2 proper's. This also means it reads in the wrong bash profile. I fixed this by adding an environment variable to Windows in the Control Panel: HOME=/C/msys64/home/myusername
I use git bash on my Windows machine and have run into this issue in the last month or so.
I still do not know what's causing it but I've found another way to stop it.
Open Task Manager
Go into the Processes tab
Look for node.exe and then press End Process
This has allowed me to stop the server quickly.
I had the same problem working with npm. But finally, I knew it was a problem with git itself.
There was a comment by dscho on GitHub 15 days ago. He said that they're working to fix this problem in the next release. He also shared the exact msys-2.0.dll file that can fix the problem for the people who can't wait.
Personally, I couldn't wait :p. So, I gave it a try, downloaded the file, and throw it in the git folder as he said. And the problem gone! It was awesome!
But please be sure to take a backup before you replace the file.
I also tried to kill it after running express as I used to; using taskkill /im node.exe on the cmd but there was no process to be found.
Check out this issue on GitHub,and search for the name of the file msys-2.0.dll to get to the comment faster.
Sometimes the node process hangs.
Check for the process ID using ps You may want to grep for node and then kill the process using kill -9 [PID]
Use Ctrl+\ to send the SIGQUIT signal. It will close the server.
Reference - https://en.wikipedia.org/wiki/Signal_(IPC)
I was able to fix this by switching to nodemon to run the server.
npm install --save-dev nodemon
package.json:
"scripts": {
"start": "nodemon app"
},
I was trying to get json-server to quit a custom server script, but it always left a child process running on Windows. It seems to be a specific problem running express via npm on Windows. If you run the server directly via the c:>node server.js then it seems to quit correctly.
I was able to debug this issue by checking the ports using TCP View, and realizing that my Node server was running even though I had pressed ctrl-C to stop it. I suggest killing the terminal you are running node from entirely.
Use Ctrl + C, then input: >pm2 stop all
This will stop all server or when you get stack with nodejs.
Inside package.json under scripts I had this line react-scripts start&. Notice it ends with an & which would send the process to the background and ctrl+c will not work. Somehow trying to bring this to the foreground with fg also did not work. Solved the problem by removing the &.
if you use Node.js Exec Extention to run your project from f8,
you can use also f9 to cancel running..
This is more than likely just a problem with your console not accurately sending the command to the process. This is pretty common, especially when using third party consoles like cmdr / conemu.
The solution?
Just hit ctrl+c several times until it closes :P

EADDRINUSE exception with node server [duplicate]

I have a simple server running in node.js using connect:
var server = require('connect').createServer();
//actions...
server.listen(3000);
In my code I have actual handlers, but thats the basic idea. The problem I keep getting is
EADDRINUSE, Address already in use
I receive this error when running my application again after it previously crashed or errors. Since I am not opening a new instance of terminal I close out the process with ctr + z.
I am fairly certain all I have to do is close out the server or connection. I tried calling server.close() in process.on('exit', ...); with no luck.
First, you would want to know which process is using port 3000
sudo lsof -i :3000
this will list all PID listening on this port, once you have the PID you can terminate it with the following:
kill -9 <PID>
where you replace <PID> by the process ID, or the list of process IDs, the previous command output.
You can also go the command line route:
ps aux | grep node
to get the process ids.
Then:
kill -9 PID
Doing the -9 on kill sends a SIGKILL (instead of a SIGTERM).
SIGTERM has been ignored by node for me sometimes.
I hit this on my laptop running win8. this worked.
Run cmd.exe as 'Administrator':
C:\Windows\System32>taskkill /F /IM node.exe
SUCCESS: The process "node.exe" with PID 11008 has been terminated.
process.on('exit', ..) isn't called if the process crashes or is killed. It is only called when the event loop ends, and since server.close() sort of ends the event loop (it still has to wait for currently running stacks here and there) it makes no sense to put that inside the exit event...
On crash, do process.on('uncaughtException', ..) and on kill do process.on('SIGTERM', ..)
That being said, SIGTERM (default kill signal) lets the app clean up, while SIGKILL (immediate termination) won't let the app do anything.
Check the PID i.e. id of process running on port 3000 with below command :
lsof -i tcp:3000
It would output something like following:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 5805 xyz 12u IPv6 63135 0t0 TCP *:3000 (LISTEN)
Now kill the process using :
kill -9 5805
For macOS Monterey(12.0):
Apple introduced some changes for AirPlay on macOS Monterey. Now, it uses 5000 and 7000 ports. If you are using these ports in your project, you need to disable this feature.
System Preferences > Sharing > untick AirPlay Receiver
For macOS Ventura(13.0) and above users:
System Settings > General > disable AirPlay Receiver
I found this solution, try it
Give permission use sudo
sudo pkill node
I usually use
npx kill-port 3000
or on my mac.
killall node
Rewriting #Gerard 's comment in my answer:
Try pkill nodejs or pkill node if on UNIX-like OS.
This will kill the process running the node server running on any port.
Worked for me.
Linux
Run ps and determine the PID of your node process.
Then, run sudo kill PID
Windows
Use tasklist to display the list of running processes:
tasklist /O
Then, kill the node process like so (using the PID obtained from the tasklist command):
taskkill /pid PID
Here is a one liner (replace 3000 with a port or a config variable):
kill $(lsof -t -i:3000)
For windows open Task Manager and find node.exe processes. Kill all of them with End Task.
I was getting this error once and took many of the approaches here.
My issues was that I had two app.listen(3000); calls in the same app.js script. The first app.listen() succeeded where the second threw the error.
Another useful command I came across that helped me debug was sudo fuser -k 3000/tcp which will kill any rogue processes you might have started (some processes may restart, e.g. if run with forever.js, but it was useful for me).
For Visual Studio Noobs like me
You may be running the process in other terminals!
After closing the terminal in Visual Studio, the terminal just disappears.
I manually created a new one thinking that the previous one was destroyed. In reality, every time I was clicking on New Terminal I was actually creating a new one on top of the previous ones.
So I located the first terminal and... Voila, I was running the server there.
Windows by Cmd
1/2. search => write cmd => open node.js command prompt
2/2. Run windows command: taskkill
Ends one or more tasks or processes.
taskkill /f /im node.exe
/f - force ended
/im - Specifies the image name of the process to be terminated.
node.exe - executable file
Windows - Mannualy by Task Manager
This command is the same as going to Task Manager under the details tab & select node tasks (Tidy in my opinion).
And end task
Visual studio
Sometimes there is more than one terminal/task (client/server and so on).
Select and close by ctrl + c.
You may run into scenarios where even killing the thread or process won't actually terminate the app (this happens for me on Linux and Windows every once in a while). Sometimes you might already have an instance running that you didn't close.
As a result of those kinds of circumstances, I prefer to add to my package.json:
"scripts": {
"stop-win": "Taskkill /IM node.exe /F",
"stop-linux": "killall node"
},
I can then call them using:
npm run stop-win
npm run stop-Linux
You can get fancier and make those BIN commands with an argument flag if you want. You can also add those as commands to be executed within a try-catch clause.
FYI, you can kill the process in one command sudo fuser -k 3000/tcp. This can be done for all other ports like 8000, 8080 or 9000 which are commonly used for development.
ps aux | grep node
kill -9 [PID] (provided by above command)
Description:
ps will give the process status, aux provide the list of a: all users processes, u: user own processes, x: all other processes not attached to terminal.
pipe symbol: | will pass the result of ps aux to manipulate further.
grep will search the string provided(node in our case) from the list provided by ps aux.
First find out what is running using:
sudo lsof -nP -i4TCP:3000 | grep LISTEN
You will get something like:
php-fpm 110 root 6u IPv4 0x110e2ba1cc64b26d 0t0 TCP 127.0.0.1:3000 (LISTEN)
php-fpm 274 _www 0u IPv4 0x110e2ba1cc64b26d 0t0 TCP 127.0.0.1:3000 (LISTEN)
php-fpm 275 _www 0u IPv4 0x110e2ba1cc64b26d 0t0 TCP 127.0.0.1:3000 (LISTEN)
Then you can kill the process as followed:
sudo kill 110
Then you will be able to run without getting the listen EADDRINUSE :::3000 errors
Really simply for all OS's ..
npx kill-port 3000
Although your problem is as mentioned above you need to catch the different ways node can exit for example
process.on('uncaughtException', (err, origin) => {
console.log(err);
});
// insert other handlers.
bash$ sudo netstat -ltnp | grep -w ':3000'
- tcp6 0 0 :::4000 :::* LISTEN 31157/node
bash$ kill 31157
PowerShell users:
Taskkill /IM node.exe /F
UI solution For Windows users: I found that the top answers did not work for me, they seemed to be commands for Mac or Linux users. I found a simple solution that didn't require any commands to remember: open Task Manager (ctrl+shift+esc). Look at background processes running. Find anything Node.js and end the task.
After I did this the issue went away for me. As stated in other answers it's background processes that are still running because an error was previously encountered and the regular exit/clean up functions didn't get called, so one way to kill them is to find the process in Task Manager and kill it there. If you ran the process from a terminal/powerShell you can usually use ctrl+c to kill it.
Task Manager (ctrl+alt+del) ->
Processes tab ->
select the "node.exe" process and hit "End Process"
Just in case check if you have added this line multiple times by mistake
app.listen(3000, function() {
console.log('listening on 3000')
});
The above code is for express but just check if you are trying to use the same port twice in your code.
In windows users: open task manager and end task the nodejs.exe file, It works fine.
On Windows, I was getting the following error:
EADDRINUSE: address already in use :::8081.
Followed these steps:
Opened CMD as Admin
Ran the folowing
command netstat -ano|findstr "PID :8081"
got the following processes:
killed it via:
taskkill /pid 43144 /f
On MAC you can do like this:
raghavkhunger#MacBook-Air ~ % lsof -i tcp:8081
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 23722 username 24u IPv6 0xeed16d7ccfdd347 0t0 TCP *:sunproxyadmin (LISTEN)
username#MacBook-Air ~ % kill -9 23722
With due respect to all the answers in the form, I would like to add a point.
I found that when I terminate a node app on error using Ctrl + Z, the very next time when I try to open it got the same error EADDRINUSE.
When I use Ctrl + C to terminate a node app, the next time I opened it, it did without a hitch.
Changing the port number to something other than the one in error solved the issue.
using netstat to get all node processes with the port they are using and then kill the only one you want by PID
netstat -lntp | grep node
you will get all node processes
tcp6 0 0 :::5744 :::* LISTEN 3864/node
and then when you get the PID (3864) just kill the processes by PID
kill -HUP PID
You may use hot-node to prevent your server from crashing/ run-time-errors. Hot-node automatically restarts the nodejs application for you whenever there is a change in the node program[source] / process[running node program].
Install hot-node using npm using the global option:
npm install -g hotnode

Categories

Resources