I am trying to run my localhost node.js server but it is not loading in any browser, i am not getting any error as well just a buffering symbol on the browser. My code is running fine on VS Code. Here is the code:
server.js code:
const http = require("http");
const app = require("./app");
const port = 3000;
const server = http.createServer();
server.listen(port);
app.js code:
const express = require("express");
const app = express();
app.use((req, res, next) => {
res.status(200).json({
message: "it works!",
});
});
module.exports = app;
This is not working for any node.js code
VS Code is running fine
No error or nothing is being shown
Same thing is happening for my html pages, images attached below:
HTML page when clicked on Go Live, but it works if i double click the file directly without vs code
Please help me out
I tried many things but it just won’t work, I re-installed node.js, I did reset my networks as well I don’t understand the problem.
2
Answers
In your code you should pass your Express App to createServer
You have defined app in server.js and never used. Simply you can use the below in the server.js file
Ive also added err to capture error.