Express Applications throwing 500 on azure - node.js

The following code runs perfectly locally...
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send("Hello World");
});
var port = 8080;
app.listen(port, function () {
console.log('Server started and is listening on port ' + port);
});
But when i deploy it to azure I get a 500 error. Here is my findings...
I have taken this advice
Have tried all possible combinations of server.js, app.js, directory structure etc.
The code is being deployed from a local git repo.

Azure Web Apps (web sites) listen on ports 80 and 443 only. You can not listen on port 8080.
You'll need to listen on port process.env.PORT. And you can easily run both locally and in Azure by tweaking your port code to something like:
var port = process.env.PORT || 8080;

Related

How to run express server on Shared Hosting?

My shared hosting doesn't allow me customization. But, I anyhow installed nodejs. I also wrote an express server code inside /var/www/test-server directory.
const express = require('express')
const app = express()
const port = 8080
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
• But, I cannot access express server
• I can't use port 80.
• When I use some other ports like 8080, then I can see console output on Terminal as below:
example.work#example:/var/www/test-server$ node index.js
Example app listening on port 8080
Now, my question is —
"Is it possible to access express server with or without port through browser?"
Like: http://example.com/test-server
You must set up NGINX for the express server to be available on a Domain.
Alternatively, you can access the server at http://ipofthemachine:port
Make sure the port you are using is exposed if you have any firewall in place.

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.

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.

Running multiple node express applications on single port

I am want to make proxy manger application for express,
but I have error all time that I try to do require for two diffrent applications.
i am using on app.use to route between the two application.
thanks alot
david
var app1 = require('./../app1/server/server');
var app2 = require('./../app2/server/server');
var app = require('express')();
app.use("/", app1);
app.use("/app2", app2);
app.listen(80, console.log("server up"))
Error is :
event,js:85 listen eaddrinuse
The port 80 is in use by another process. try with another empty port like 8080 or 3000. You can also try by stopping the application that is using port 80, then it will work.

Nodejs port 8000 ,4000 not working on server

I am using nodejs for rest-api and my app running on 2000,3000 but when i use port 8000 it work on browser but it not working on iphone also i was opened port 8000 from whm.
Try to run your application on 0.0.0.0 ip address, this guarantees it would be listening on all the configured network interfaces
var server = app.listen(8000, '0.0.0.0', function () {
var host = server.address().address;
var port = server.address().port;
console.log('App listening at http://%s:%s', host, port);
});

Resources