Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!