Error when launching react native app with emulator - javascript

I'm trying to launch my react native project for the first time, I have installed everything that is noted on the documentation on react native to use android studio when I run the emulator and I do this command:
npx react-native start
it's giving me this error in the terminal:
error listen EADDRINUSE: address already in use :::8081.
Error: listen EADDRINUSE: address already in use :::8081
at Server.setupListenHandle [as _listen2] (net.js:1313:16)
at listenInCluster (net.js:1361:12)
at Server.listen (net.js:1449:7)
at C:\Users\pc\Desktop\AwesomeProject\node_modules\metro\src\index.js:279:18
at new Promise (anonymous)
at Object.anonymous
(C:\Users\pc\Desktop\AwesomeProject\node_modules\metro\src\index.js:278:12)
at Generator.next (anonymous)
at asyncGeneratorStep
(C:\Users\pc\Desktop\AwesomeProject\node_modules\metro\src\index.js:68:24)
at _next (C:\Users\pc\Desktop\AwesomeProject\node_modules\metro\src\index.js:90:9)
info Run CLI with --verbose flag for more details.

This happens when some process is already running on the same port which react is using. We need to kill that process , so our port will be free.
To kill Process :
netstat -ano | findstr :
Now you will get some integer number that is Process ID OR PID: ex: 34573 ,94982.
Just copy the PID.
taskkill /PID <YOURS_PID> /F
example: taskkill /PID 345872 /F
Run app again.

If you are beginning with react native expo might be a better start: expo
Fix: There might be another service using port 8081, if it‘s another node service you can kill it with taskkill /f /im node.exe

Related

Starting inspector on localhost:9229 failed: address already in use

I'm running a node server using "http.createServer", running on port 3001, when I serve the server the first time it runs, and when I do a small change no matter what I get an error said :
**Starting inspector on localhost:9229 failed: address already in use
Server started on http://localhost:3001
Error: listen EADDRINUSE: address already in use :::3001
at Server.setupListenHandle [as _listen2] (node:net:1372:16)
at listenInCluster (node:net:1420:12)
at Server.listen (node:net:1508:7)**
about the 9229 - tried to investigate it by running
lsof -i :9229
and saw that there is 2 instances of it :
node 88370 33u IPv6 0x**************** 0t0 TCP localhost:9229 (LISTEN)
node 88370 34u IPv4 0x**************** 0t0 TCP localhost:9229 (LISTEN)
when I killed it, it created again and again on each code change, this is the first issue.
the second is regarding: "address already in use :::3001.." what is wrong here? I'm listening to that port -
server.listen(3001);
do you have any ideas where to investigate it maybe?
thanks!
about the second issue i tried to change ports.

Nodejs Error: listen EADDRINUSE: address already in use :8080

My app was not running but when I try "npm start" command it throws error
Error: listen EADDRINUSE: address already in use :8080
I restart my EC2 instance and try this command again, but I face same error. How do I start my Node server?
Going by your comments, it looks like you have a node process already running your EC2 instance and it's listening on port 8080.
As you have stated lsof -i tcp:8080 gives you,
node 3255 root 20u IPv6 20660 0t0 TCP *:webcache (LISTEN)
The PID of this process is shown in the 2nd column: 3255.
Kill it,
kill -9 3255
After this try running your npm start and it should work

Running json-server in docker

I've been running json-server in a docker container for a while successfully with the following config:
Docker File:
FROM node:alpine
EXPOSE 3000
COPY deploy/conf/mockBackend.json /opt/mockBackend.json
RUN yarn global add json-server
CMD ["json-server", "/opt/mockBackend.json"]
Run command:
docker run -d -p 3000:3000 --name mockbackend mockbackend
Recently this stopped working. I get ERR_CONNECTION_REFUSED
in the browser.
By default json-server binds to 127.0.0.1, which could cause this issue if this is correct.
I don't know why it worked before, but binding json server to every interface with json-server -H 0.0.0.0 mockBackend.json makes it work again.
My problem now is that starting json-server that way in the image manually works fine, but when I change the CMD line of the Dockerfile to CMD ["json-server", "-H 0.0.0.0", "/opt/mockBackend.json"] I get the folloing error:
Docker log:
\{^_^}/ hi!
Loading /opt/mockBackend.json
Done
Resources
http:// 0.0.0.0:3000/xxx
http:// 0.0.0.0:3000/yyy
Home
http:// 0.0.0.0:3000
Type s + enter at any time to create a snapshot of the database
events.js:167
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND 0.0.0.0
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:50:26)
Emitted 'error' event at:
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1498:12)
It looks like the json-server is starting fine, but then exits with the error. Any idea why this only happens when starting the container with the CMD line, but not when running the same json-server command manually inside the same image?

Error: listen EADDRINUSE in nodejs

I've created javascript build system in sublime using that
Then I run server using that code
var server = require('http');
function engine(request, response){
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end("Hello");
}
server.createServer(engine).listen(3000);
but when I'll make change and for example will change Hello to Hello World and refresh browser it doesn't make any sense and when I'm trying rerun (f7) it throws an exception
events.js:141
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3000
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at Server._listen2 (net.js:1231:14)
at listen (net.js:1267:10)
at Server.listen (net.js:1363:5)
at Object.<anonymous> (C:\Users\gsiradze\Desktop\nodejs\script1.js:4:8)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
[Finished in 0.1s]
I know that it's because of 3000 port is in use but how can I stop that port an then run the new code?
I'm pretty new at node.js, so feel free to give any suggestion
How do you run the nodejs implementation?
You could try to use the package nodemon
npm install -g nodemon
Now you can start your node application by typing nodemon in the directory.
If you change and save your file now, the server will automatically restart your server.
If you dont want to use nodemon, shut down the server with ctrl+c
server.createServer(engine).listen(3000);
that's where you say where port is located, you can change port to any other one.
To rerun your code, I take it you use console you can press ctrl+C to stop process and run it again with node nameOfYoursServerFile.js
Find what is the PID of your process on 3000 with lsof -w -n -i tcp:3000
Then, just kill it with kill -9 PID switching PID with the PID returned by the first command.
You need to get the PID of node service
You can do that by running this command on your terminal
ps aux | grep node
it will give you id of running node process
and the you can use
kill -9 <id of node process>
to stop node process and then try again to run your node server
Either Ctrl+C the foreground process or find your running process's ID by using pidof node and then killing it (kill pid). Even if you are running with forever or in the background some other way, this will work.

Node.js throws er Unhandled error event

I have installed node, npm in my Centos 6 server, and i am using putty for running commands at server.
Node is installed correctly at root and running awesome at anywhere at server.
my project is at /home/shaadise/public_html/Ikon
I have created a hello.js file /home/shaadise/public_html/Ikon
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8080);
console.log('Server started');
while running js:
root#vps [/home/shaadise/public_html/Ikon]# node hello.js
Server started
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1042:14)
at listen (net.js:1064:10)
at Server.listen (net.js:1138:5)
at Object.<anonymous> (/home/shaadise/public_html/Ikon/hello.js:6:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
root#vps [/home/shaadise/public_html/Ikon]# throw er; // Unhandled 'error' event
-bash: throw: command not found
-bash: //: is a directory
Question: where i have to put my node js file and how can i access it????
i tested to run command:
root#vps [/home/shaadise/public_html/Ikon]# netstat -plnt | grep ':8080'
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 27111/nginx
This Error: listen EADDRINUSE categorically means that either you or a daemon is running another application on 8080.
However, to check, try running on a different port?
-edit- as this is getting quite a few upvotes, I thought i'd add a bit of additional debug into it.
Pretty much all node.js tutorials default to port 8080 for running. This is because it is similar to the default port 80 used by other web services, such as Apache or NGinX.
In order to determine if another application is running on the same port, you can use netstat -a to see all active connections and their ports, and then grep that list to find any process connected on the same port as your Node.js application.
It doesn't really matter which port your Node application runs on, as long as it's a free port. Ultimately, when you deploy into production, you would sync up whatever content server you are using (Apache/NGinX) to use the same port.
A common situation to get this error is when one does the following:
startup something
use Ctrl+z and put it into background
try to startup something again
The good way to go would be always try to hit Ctrl+c first which sends signal to the application (which may decide to shutdown).
You can read more about it here:
What is the difference between Ctrl-z and Ctrl-c in the shell?
The server is running in background; it's happing, usually, when you don't kill the process.
To solve this you can put on the terminal:
ps | grep 'node'
This code will show you a process that have a specific number, use the next code to kill the process:
kill -9 "specific number"
You can use sudo if this doesn't work correctly.
If you are using Linux based system, first you have to list all the programs that are using that particular port and kill them(meaning stop them)
exemple: I want to list all programs that are using the 3000 port
fuser 3000/tcp
then pick the process ID, which is in the right side of the obtained line of text and issue the kill command
exemple : if have a process ID with the value of 2345 then the command will be
kill 2345
If closing the process which is using that port doesn't fix it , try the below solutions.
Installing the below package fixed it for me forever.
npm install ws#3.3.2 --save-dev --save-exact
Run this command in your terminal :
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
For Arch Linux add this line to /etc/sysctl.d/99-sysctl.conf:
fs.inotify.max_user_watches=524288
Then execute:
sysctl --system
https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers#the-technical-details

Categories

Resources