Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way for me to supply the http server in NodeJS with an html file for hosting?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading