0

Current code below

const http = require('http');
const server = http.createServer(function(req, res) {
  res.setHeader("Content-type", "application/json");
  res.setHeader("Access-Control-Allow-Origin", "*");
  res.writeHead(200);
  res.end("Ping server page");
});

server.listen(8080, function() {
  console.eblue("\nListening on port 8080");
  console.eblue("WEB SERVER STARTED\n");
});

I just want to know if their is a way to make a fully featured site and host it using node.js

Gavin H
  • 3
  • 2
  • Sure. But you probably want to have a look into https://expressjs.com/ – eyecatchUp Feb 03 '22 at 17:22
  • Does this answer your question? [Node.js send file in response](https://stackoverflow.com/questions/10046039/node-js-send-file-in-response) – Seblor Feb 03 '22 at 17:24

2 Answers2

0

Yes (if I understood correctly), you just need to serve the html as a static file like this:

https://expressjs.com/en/starter/static-files.html

Meddah Abdallah
  • 654
  • 1
  • 7
  • 25
0

I recommend using Express (a node.js package) for web servers, which you can then serve static files - including HTML - through with express.static.

Joe
  • 331
  • 1
  • 7