E
E
Egor Trubnikov-Panov2014-07-04 14:26:54
JavaScript
Egor Trubnikov-Panov, 2014-07-04 14:26:54

How to serve static server to node.js ?

there are several html and you just need to give them to the appropriate requests to the server

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2014-07-04
Protko @Fesor

There are modules like node-static . You can simply implement it on express.js ... And even easier - use nginx

I
Ivan Starkov, 2014-07-04
@icelaba

npm install express --save
in code
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/public'));
app.listen(3000);
But it’s better not to be perverted and install nginx for statics,
here you will have both caching and gzip and a hundred times more convenient.
It makes no sense to use a node even in a test configuration as a statics server

K
Klimashkin, 2014-07-29
@Klimashkin

express.static cannot be used in production due to a known problem with the lack of a queue for opening descriptors with a large number of requests, they will start to fall off. Use node-static
For gzip, use compression , you can use it separately, you can use it together with express (don't forget to put it before static).
But they said it right, it’s still better on the production side that nginx distributes the statics

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question