U
U
Umid2017-01-31 23:04:29
Node.js
Umid, 2017-01-31 23:04:29

How to correctly specify the path to the view?

Whole code:

var express = require('express');
var http = require('http');
var handlebars = require('express-handlebars').create({defaultLeyout: 'main'});

var app = express();
var server = http.createServer(app);

app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');


app.get('/', function(req, res) {
  res.render('home');
});

app.get('/about', function(req, res) {
  res.render('about');
});

app.use(function(req, res) {
  res.status(404);
  res.render('404');
});

app.use(function(err, req, res, next) {
  console.error(err.stack);
  res.status(500);
  res.render('500');
});

server.listen(3000, function() {
  console.info("Express server on port 3000");
});

If you arrange the files in the hierarchy in views/layouts/smth.handlebars , then express does not see the files, that is, it does not go down below.
I just had to put the files in views/ , and now everything is in a bunch.
How can I make it go down the folders?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
Umid, 2017-01-31
@DarCKoder

res.render(folder/file.handlebars)
Answer found.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question