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.
Related
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.
I using windows 10 and want to run nodejs on port 3000 in my public address (just of me and for remote debugging).
So I open the port as say by this answer and I run this code from expressjs
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
Then I get myip address, and tell my friend to open http://256.266.266.266:3000/ in his chrome browser.
But the answer is This site can’t be reached ERR_CONNECTION_TIMED_OUT. why? how do I connect to my nodejs application in my public ip?
I do not have any antivirus or firewall as far as I know.
Telnet telnet 256.266.266.266 3000 say .Could not open connection to the host, on port...
netstat -an | find "3000" say TCP 0.0.0.0:3000 0.0.0.0:0 LISTENING
I'm totally new to Node and I tried to run a test site on a hosting centos 7 (vultr.com). I've got nodejs, express installed.
Hello.js
const express = require('express')
const app = express()
app.get('/', function (req, res) {
res.send('Hello World!')
})
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})
run node hello.js
On my PC, http://x.x.x.x:3000/ => shows This site can’t be reached
x.x.x.x took too long to respond.
UPDATE:
I think you should consider about your server port. Have you open port 3000 in CentOS?
You can check your open port by typing
iptables -L
I think the firewall blocked your port you can open it by type this command
iptables -A INPUT -p tcp --dport 3000 -j ACCEPT
If you are using remote server, probably your 8080 port is blocked.
If you have root access and port 80 is open you can try and run script with sudo
But the first option is probably your problem
If you use the Google Cloud platform, you can open port 3000 at FIREWALL RULES in VPC network.
It works for me.
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;
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.