Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda