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

130
Views
Node/Express: Database being printed on screen rather than index.html

So, I'm using Node, but all that's printed on the screen is my database in JSON format and not index.html. This doesn't occur when I use localhost, so I have no idea why it does show my index page. Can anyone help me?

My code:

const app = express();
app.listen(3000, () => console.log('listening'));

app.get('/api', (request, response) => {
    db.find({}, (err, data) => {
        response.json(data);
    });
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I didn't exactly understand your question properly but based on the code you will get a JSON response on localhost:3000/api and a blank screen on localhost:300 as you have not rendered or called for any views in your code.

You can use app.use(express.static(__dirname + '/public')) to access your directory and then use res.sendFile('index.html') to render index HTML file on any route you wish.

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!