Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
How to build a express api in es6 script?

I use the express generator build a no-view rest api first. Then I change the whole things to es6 script and let it compile by babel.

When I enter the localhost after the changes, it says:

No default engine was specified and no extension was provided

And I found out it's because of this part of code.

router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

The error disappear when I change the res.render to res.json

I just wondering do I have to assign a view engine if I use the babel to compile my project? Even It's a no view api?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To use views on express you need to configure it to use some engine (pug, ejs, handlebars), refer to the documentation to know how it works.

The error that you mentioned

No default engine was specified and no extension was provided

means that you didn't configure any view engine, also, the template file is missing the extension, (i.g. index.pug).

When you use res.render('index', { title: 'Express' }); you are calling the view engine to render the template index and passing some values to use in it { title: 'Express' }, the result is a HTML content.

On other hand, when you use res.json({ title: 'Express' }) you are returning a json object, that's the difference.

Here is the link to the documentation of each one:

res.render

res.json

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda