J
J
John Gault2015-11-27 04:10:03
Node.js
John Gault, 2015-11-27 04:10:03

Running a local site via node server?

I immediately apologize for such ridiculous questions, but I didn’t have to work with servers before and please explain how to run my local site through the node server. I have a directory with index.html and server.js files with code

var http = require("http");

http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World 11");
  response.end();
}).listen(8888);

I started the server in this directory and everything works, but now how do I open my index.html file in this server?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2015-11-27
@Fargal_1

how to open my file in this server now
This is called serve static content. By default, there is no such functionality, but it is very simple to do it: read the file on the appropriate request and send it via response.write. To make it even easier and with goodies, there is a serve-static package , everything is described in the examples there.
Well, or not to write code at all, you can do this: https://www.npmjs.com/package/static-server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question