I
I
Ingerniated2017-03-19 11:08:48
Node.js
Ingerniated, 2017-03-19 11:08:48

Why is the nginx and fs node not designed to load html?

Guys, tell a newbie please
Why do we need an nginx node, if we are on a node and write a server like that?
And require("fs")it serves exclusively for downloading files, and not the html code of the page?
Everywhere it is customary to design html code directly in the js file and through ' ' with +?
But how to load styles here?
It seemed to me that fs should have done this, but I never saw a full-fledged example.
And what does Handler mean? Why is it called that in many languages ​​and what does it imply?
I didn't see it as a method, but as a name it is used a lot.

var querystring = require("querystring"),
  fs = require("fs"),
  formidable = require("formidable");

function start(response) {
  console.log("Request handler 'start' was called.");

  var body = '<html>'+
  '<head>'+
  '<meta http-equiv="Content-Type" '+
  'content="text/html; charset=UTF-8" />'+
  '</head>'+
  '<body>'+
  '<form action="/upload" enctype="multipart/form-data" '+
  'method="post">'+
  '<input type="file" name="upload" multiple="multiple">'+
  '<input type="submit" value="Upload file" />'+
  '</form>'+
  '</body>'+
  '</html>';

  response.writeHead(200, {"Content-Type": "text/html"});
  response.write(body);
  response.end();
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2017-03-19
@Ingernirated

Your code example is ....))) In general, you don't need it anymore =)
Thank God it's not accepted like that anywhere))

But how to load styles here?
It seemed to me that fs should have taken care of this,

fs is not required to load styles. Its task is to read and write files.
Handler is a handler. This is the name of methods and functions that process something.
Nginx for Node.js is used to proxy requests. And he gives statics much better. Yes, and very convenient. And leave node privileges to process requests to api.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question