V
V
Vyacheslav Lebedev2015-04-09 17:09:22
Node.js
Vyacheslav Lebedev, 2015-04-09 17:09:22

How to render html in nodejs?

Good afternoon!
I do it like this:

app.set('view engine', 'html');
app.use(express.static(__dirname + '/public'));
app.get('/', function (req, res) {
    res.render('index.html', {
        isMain: true
    });
});

In views/lie Static files .html
are public/located (styles, scripts, fonts)
Error:
TypeError: undefined is not a function
   at View.render (/home/slavikse/Документы/coding/shop/node_modules/express/lib/view.js:93:8)
   at EventEmitter.app.render (/home/slavikse/Документы/coding/shop/node_modules/express/lib/application.js:566:10)
   at ServerResponse.res.render (/home/slavikse/Документы/coding/shop/node_modules/express/lib/response.js:938:7)
   at /home/slavikse/Документы/coding/shop/build/main.js:19:9
   at Layer.handle [as handle_request] (/home/slavikse/Документы/coding/shop/node_modules/express/lib/router/layer.js:82:5)
   at next (/home/slavikse/Документы/coding/shop/node_modules/express/lib/router/route.js:110:13)
   at Route.dispatch (/home/slavikse/Документы/coding/shop/node_modules/express/lib/router/route.js:91:3)
   at Layer.handle [as handle_request] (/home/slavikse/Документы/coding/shop/node_modules/express/lib/router/layer.js:82:5)
   at /home/slavikse/Документы/coding/shop/node_modules/express/lib/router/index.js:267:22
   at Function.proto.process_params (/home/slavikse/Документы/coding/shop/node_modules/express/lib/router/index.js:321:12)

.render()for jade it works as it should. I don’t understand how to make it work in html too?
Thanks for any help!
Decision:
app.use(express.static(__dirname + '/public'));
res.sendfile(__dirname + '/index.html');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Demin, 2015-04-09
@slavikse

If I understand correctly - you want to pass the html file to the client side (force :D).
If so, then static html files do not need to be "rendered", it will be enough just to read them and give the contents to the client.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question