Error on npm start on Azure - EADDRNOTAVAIL - node.js

I'm trying to get a nodejs app running on Azure (which runs perfectly fine on Heroku).
After running npm start on the app, the following error happens:
Error: connect EADDRNOTAVAIL 127.0.0.1 - Local (0.0.0.0:56256)
at internalConnect (net.js:907:16)
at defaultTriggerAsyncIdScope (internal/async_hooks.js:301:12)
at net.js:998:9
at processTicksAndRejections (internal/process/task_queues.js:75:11) {
errno: 'EADDRNOTAVAIL',
code: 'EADDRNOTAVAIL',
syscall: 'connect',
address: '127.0.0.1'
}
I've tried setting various ports which are free, but no matter what, I get this error.

UPDATE
I know that your current program runs normally in Heroku, and it runs very well locally.
But what I want to tell you is that in azure webapp, there is no need to execute the npm start command to start the webapp. After you pass the deployment, you can set the Startup Command in the portal to start your application. For general nodejs projects, the startup command is npx serve -s.
So you said that the execution of npm start produces an error. If you execute this start command in kudu, it is inappropriate.
If an error occurs when running locally, such as connect EADDRNOTAVAIL 127.0.0.1-Local (0.0.0.0:56256), it is recommended that you use netstat -ano|findstr "56256" to check which process uses the port and deal with.
PRIVIOUS
You need to macke sure use process.env.PORT || 3000 in your project. And you need to know, the port in azure webapp just support 80 and 443. So in your project, So in your code, there can only be one PORT value. After deployed, 443 and 80 will work.
And you can run your app perfectly on HeroKu. So I suggest you upload your code to github.
Then you can deploy your webapp by git. And your issue will be solved. If also have error when deploy, you can check the error in Action on git.

Related

Deploy node.js in hostinger VPS but not running

I have my node app upload into hostinger and npm start run well.
But I still can't access http://my-ip:3000
node and npm and mysql have been installed
but no luck.
Am I missing some important steps?
this problem could come from your code || network
pm2 logs
see if there are some error logs
check on vps that if your service online
curl http://127.0.0.1:3000
if no resposne, you should fix the service code
check if your service runs on the right port
netstat -an | grep 3000

PeerJS Server 404 on Azure

I'm trying to deploy a PeerJS server on Azure. On my kudu console, running
node peerjs --port 9000
returns
Started PeerServer on ::, port: 9000, path: / (v. 0.2.8)
However, when I try to connect to the server from my client code, I get a 404. Going directly to appname.azurewebsites.net/peerjs/id in my browser also returns a 404.
I see inside their package.json file, they run
bin/peerjs --port ${PORT:=9000}
instead of just passing in 9000 directly; I assume this is an environment variable. However, trying to run this on Azure gives
Error: Error: listen EACCES ${PORT:=9000}
which I assume means Azure doesn't recognize ${PORT:=9000} as a valid port.
I know for a fact there's nothing wrong with my client side code because a) I copied it directly from PeerJS's website, and b) everything works correctly when I deployed PeerJS to Heroku. It's only not running on Azure.
Other things I've tried: I edited peerjs in the bin folder to use process.env.PORT instead of what's passed in via the command line, but that didn't work, giving the same EACCES error. When I tried to console.log(process.env.PORT), I got undefined. None of my Google searches have turned up any solutions, although this person (Custom PeerJs Server giving ERR_CONNECTION_TIMED_OUT) seems to have a similar error, not on Azure.
Azure App Service doesn't allow us to listen on a customer port. We need to use process.env.PORT instead. See Listen additional port Microsoft Azure Nodejs.
Azure App Service (on Windows platform) runs on Microsoft IIS. So we need to put the app files to its virtual directory (D:\home\site\wwwroot) and no longer need to manually run the app via the Kudu console.
In this case, you first need to install the library under app's root:
npm install peer
And then create a file named index.js or app.js with following content and put it to /wwwroot folder:
var PeerServer = require('peer').PeerServer;
var server = PeerServer({port: process.env.PORT, path: '/'});
As #Mikkel mentioned in a comment, PeerServer uses WebSocket protocol, so Web Sockets should be enabled in the Azure portal like this:
You also need to check out this post to add a web.config file for your app if it has not been created yet.
This will be a firewall problem... You will need to open port 9000 in your Azure settings panel.
From the machine itself, open up a browser to http://localhost:9000/ or http://localhost:9000/peerjs and you should see the standard Peerjs server JSON output.
Or if you only have command line, try curl http://localhost:9000/ or http://localhost:9000/peerjs

I get a EADDRINUSE error when I try to start a node.js server on OpenShift

So, I successfully commited a node.js app to OpenShift - without getting any error - but it does not work (error 503 when trying to access it through my browser, connection timeout when running tests against it from my local machine). The output when commiting says that node and mysql start successfully, and that the build succeeded.
I accessed the server through ssh, and checked the node log. It says an EADDRINUSE occured: Error: listen EADDRINUSE :::8080.
In my configuration, I use:
"server":{
"host":"OPENSHIFT_NODEJS_IP",
"port":"OPENSHIFT_NODEJS_PORT"
}
I also checked available environement variables in the shell with export and both are there, and 8080 is the right port.
When running ps in the shell, it does show only the programs ps and bash running. EADDRINUSE should mean that the port is already in use by another program, but I don't see anything running... I can't run netstat (permission denied).
I tried various combinations of stop/start/restart, but I always get the same error.
I am pretty lost at this point. Any pointers would be appreciated!
I found the problem. Locally, I used to start the server with app.listen(port);, which is enough to run it and access it on localhost. But that does not work on OpenShift. The host needs to be specified too: app.listen(port, host);.

Deploy meteor app in Azure on Windows

Hello i am have meteor app and want deploy on Azure on Windows, i try it by Meteor Up but can't do it
***\project2>npm install -g mup
***\project2>mup init
Meteor Up: Production Quality Meteor Deployments
------------------------------------------------
Empty Project Initialized!
***\project2>mup setup
Meteor Up: Production Quality Meteor Deployments
------------------------------------------------
Started TaskList: Setup (linux) [23.101.74.119] - Installing Node.js events.js:85
throw er; // Unhandled 'error' event
^ Error: connect ETIMEDOUT
at exports._errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1000:19)
this error in Command Prompt of window from my local system
Looking at the error description it might be a connectivity issue. If you could share your mup.json file we might be able to spot the issue there.
Did you create an endpoint on TCP port 80? Check you nodeVersion setting so it corresponds to you Meteor app. The ROOT_URL should be in the format http://[myappname].cloudapp.net.
Using mup logs -n 50 you might detect some clues.

Unhandled rejection SequelizeConnectionError: connect ENOENT

I am stuck at a point. I am trying to start /connect using command "npm start" but unable to start npm on server.
I am getting this error:
Unhandled rejection SequelizeConnectionError: connect ENOENT
at Handshake._callback (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:63:20)
at Handshake.Sequence.end (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
at Protocol.handleNetworkError (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/mysql/lib/protocol/Protocol.js:358:14)
at Connection._handleNetworkError (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/mysql/lib/Connection.js:382:18)
at Socket.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:442:13)
Apart from this my website work on nodejs & have nginx server configured on server.
Every thing started when I tried to set apache for adding a wordpress blog website. Since nginx already working on port 80. I was trying to set apache on another port so that everything work and ended up with above error. Now my website is not starting at all.
Edit:
My website is running using nodejs. I needed a wordpress blog website to run along and so i checked if there is a scope for apache on my server.
I found that apache along with nginx service was already running and mysql as well.
nginx is essential to run "adminer", a database management tool
Since nginx and apache was running on same ports, i tried to set apache on another port, other than default port.
After that I restarted apache, stopped mysql, stopped nginx and also stopped node
I used pkill node command for stopping node service.
Then restarted everything but got the above error.
I tried many things, and finally reset everything.
Ever since then I am stuck on this error.
Can anyone help?
I finally figured the problem and solved it.
Connect ENOENT means that system is unable to connect to mysql because its path is not correct.
As mentioned in an approved answer from Connect MySQL with Sequelize
Update your models/index.js file with the mentioned code.
To find you mysql socket path go to file here /etc/mysql/my.cnf ( this path may depend on your server). For my case it was /etc/my.cnf. Here you will find the socket path. Now paste this path to the code above and do npm start.
Problem is resolved. :)

Resources