Answer the question
In order to leave comments, you need to log in
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
});
});
views/
lie Static files .html
public/
located (styles, scripts, fonts) 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? app.use(express.static(__dirname + '/public'));
res.sendfile(__dirname + '/index.html');
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question