I'm trying to understand how nodejs server works and how to get NodeJs server to send an Html when I send a request to do it.
I have a nodejs with express in a VPS. In the same VPS i host a webpage through vesta. I have a code to listen in one port (4000) and I want it to send an Html. when I run the node file I have the feedback that server is listening, but when I type the IP of the webpage and the port in my browser (IP:4000) I get This site can’t be reached.
I'm not using port 8080 because that port is already in use by HTTP and I get the error listen EADDRINUSE :::8080
What am I missing?
const express = require('express');
const app = express();
const PORT = 4000;
app.get('/about', (req, res) => {
res.sendFile('./views/page.html', { root: __dirname });
});
app.listen(PORT, () => {
console.log(`Server running at: http://localhost:${PORT}/`);
});
CodePudding user response:
Make sure that your VPS is listening to port 4000.