PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 1, 2022

[FIXED] Why i don't see response when I type in browser IP and port where nodejs is listening?

 August 01, 2022     express, html, node.js, server, vps     No comments   

Issue

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}/`);
});

Solution

Make sure that your VPS is listening to port 4000.



Answered By - Elzohary
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing