Im getting Listen EACCES on my nodejs app - linux

Im new in linux, so I got a aws amazon server and install nodejs and mongodb in var/www/html .
Dir:
-var
-www
-html
-server.js
-public
-node_modules
-express
-mongodb
-mongoose
In my server.js:
var express = require('express');
var app = express();
app.use(express.static(__dirname + "/public"));
app.listen(8080);
When I run:
$ node server
I get this error:
Error: listen EADDRINUSE
at errnoException (net.js:905:11)
at Server._listen2 (net.js:1043:14)
at listen (net.js:1065:10)
at Server.listen (net.js:1139:5)
at EventEmitter.listen (/var/www/html/node_modules/express/lib/application.j s:617:24)
My app is running in port 8080.But I cant run mongosee with this error. Can u help me guys?

Looks like the port 8080 is already in use. Try to set different port to your program temporarily:
app.listen(8085);
If the problem disappear you need to find which program is using port 8080. You can use netstat -tulpn for such task.

Related

I can't understand Why I can only connect to 8080 port in node Js express server

const express = require('express');
const app = express();
app.set('port', process.env.PORT || '3000');
app.get('/', (req,res)=>{
res.send('Hello Express');
});
app.listen(app.get('port'),()=>{
console.log(app.get('port'),'listening');
})
Hi, I started studying nodeJs but got a problem.
If I run the server this way,
$ node app.js
8080 Listening
There's no problem in connecting to this server.
However, I got a problem if I run the server after changing the port.
$ PORT=3001 node app.js
3001 Listening
It seems working without problem but I can't connect to 3001 port. So I tried other ports but neither worked. I can't understand why only 8080 port is available.
I'm developing by using AWS cloud9 IDE and Ubuntu 18.04.5 LTS.

NodeJS on Ubuntu 20.04 - Cannot start server because address in use (:::80) but I can't find any port listening to that address

When running the following command:
sudo node server/server.js
I receive the following error:
Listening on port 80 events.js:174
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::80
at Server.setupListenHandle [as _listen2] (net.js:1280:14)
at listenInCluster (net.js:1328:12)
at Server.listen (net.js:1415:7)
at Function.listen (/home/app/node_modules/express/lib/application.js:618:24
However when looking at similar questions I was advised to find the process using the port and end it.
When running on root and regular user the following command:
lsof -n -i:80
as well as
netstat -tulpn | grep :80
I get 0 results and no output returned.
Killing the node daemon (using pkill node) and then restarting it didn't work either.
Changing the port gives the same error strangely:
Error: listen EADDRINUSE: address already in use :::8080
Why am I still getting this error?
EDIT The Server Code:
// optional: allow environment to specify port
const port = process.env.PORT || 80;
// wire up the module
const express = require("express");
var http = require("http");
var request = require("request");
// create server instance
const app = express();
// bind the request to an absolute path or relative to the CWD
app.use(express.static(path.join(__dirname, "../dist")));
app.use(express.json());
app.listen(port, () => {
console.log(`This app is listening at http://localhost:${port}`);
});
...
Hi can you upload the server.js content .
You have to run your http server in a other port or try to stop nginx or Apache2 service if you installed them
Simply Kill the Process::
sudo kill $(sudo lsof -t -i:8080)
where replace 8080 with your address and then rerun your app.
If you want to know all the port or address in use simply install nmap from ubuntu snap store and scan all the port using terminal with command
nmap localhost

Run first Nodejs app on cpanel godaddy hosting

I'm trying to run my first Node.js application, but I'm having trouble. This could be an error with the firewall on CPanel, but I'm not sure.
I'm running Node.js version 5.0.0
And this is my js:
var net = require('net');
var server = net.createServer(function (socket) {
socket.write('Open Serverrn');
socket.pipe(socket); });
server.listen(674, 'my.ip.add.ress');
console.log('Server running at http://my.ip.add.ress:674/');
And final : this is my notification :
node test.js
Error is:
Server running at http://my.ip.add.ress:674/
events.js:141
throw er; // Unhandled 'error' event
^
Error: listen EACCES my.ip.add.ress:674
at Object.exports._errnoException (util.js:860:11)
at exports._exceptionWithHostPort (util.js:883:20)
at Server._listen2 (net.js:1221:19)
at listen (net.js:1270:10)
at net.js:1379:9
at doNTCallback3 (node.js:461:9)
at process._tickCallback (node.js:367:17)
at Function.Module.runMain (module.js:459:11)
at startup (node.js:136:18)
at node.js:972:3
When I open my console with port 674, it's always loading and timing out after a few seconds. Why is that? Plz help me this issue.
I do not believe GoDaddy has Node.js support, as per this: How to install nodejs application in Godaddy server
Common hosts for Node apps would be:
Digital Ocean, Nodejitsu (owned by GoDaddy anyway), Modulus, Heroku, Joyent, and AWS, I believe.
You need to use port higher than 1024. To bind lower ports you need root privileges or allow program to bind via setcap - can't be implimented at GoDaddy or other shared hosting.

Openshift - port to use on deployment

I have the following start.js file:
var express = require('express');
var app = express();
app.use(express.static('static'));
var server = app.listen(8080, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
In my NodeJs application on Openshift. However, when I run rhc tail-a app-name
I can see that there is an error of :
Error: listen EADDRINUSE :::8080
I've tried 80 and 443, and received those errors:
Error: listen EACCESS 0.0.0.0:443
Or 80
Which port should I use as default on my app?
Thanks!
Use Nginx,
Nginx (pronounced "engine x") is a web server. It can act as a reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer and an HTTP cache.
It isn't good practice to run your application with root privileges or directly run your application on port 80 and your port 8080 is in use. Try different port and use reverse proxy.
But if you want to run on port 80 or 443, run your application with root privileges.

EADDRNOTAVAIL when Dockerizing Node.js app

With the following app, I am able to start it manually via npm install / node app.js. The issue is with trying to run the app via a Docker container.
Apart from what the rest of the app is (which doesn't matter because running the Docker container doesn't even get that far), the Dockerfile pulls the code from GitHub, switches to that directory, then runs app.js (which pulls the host and port from a config.json file). Attempting to run the container with the IP address of the server (what it should be listening on) results in the following error:
uncaughtException: Error: listen EADDRNOTAVAIL
Error: listen EADDRNOTAVAIL
at errnoException (net.js:905:11)
at Server._listen2 (net.js:1024:19)
at listen (net.js:1065:10)
at net.js:1147:9
at dns.js:72:18
at process._tickCallback (node.js:442:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:929:3
Changing the port does nothing to resolve the issue. I've included the relevant files below (with certain sections replaced with {pseudocode}). Any help would be immensely appreciated, because I'm absolutely hopeless when it comes to Docker.
Dockerfile:
FROM centos:centos6
RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
RUN yum install -y npm git
RUN git clone {repo.git}
COPY . /src
RUN npm install
CMD ["node", "app.js"]
config.json:
{
"app_host": "{IP of server}",
"app_port": "20000"
}
app.js:
var server = app.listen(config_json.app_port, config_json.app_host, function () {
var host = server.address().address;
var port = server.address().port;
console.log('\n listening at http://%s:%s', host, port);
});
module.exports = app;
Turns out robertklep in the comments to my question was correct: the issue was trying to explicitly pass the IP of the server into app.js. That's the way the app was configured to work just by itself with Node, but that can't be done with Docker.
The only code change needed was removing config_json.app_host from app.listen in app.js. Then, running the container by binding the exposed port to any available port on the server causes it to work.

Resources