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

171
Views
El enrutador doméstico "/" en express-generator se está sobrescribiendo en alguna parte, o simplemente no funciona. ¿Por qué?

Estoy tratando de conectar mongodb con express-generator . Mi enrutador doméstico predeterminado "/" está en index.js, pero no funciona. No se invoca. Solo funciona si cambio el enrutador a otra cosa.

 var express = require('express'); var router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { console.log('here') const collection = req.app.locals.collection; collection.find({}) .toArray() .then(data => res.json(data)) }); module.exports = router;

Este es mi index.js.

Y en mi app.js, tengo esto:

 var indexRouter = require('./routes/index'); MongoClient.connect(uri, (err, client)=>{ if(err) console.log('we have an error: ', err) const db = client.db('MovieGoers'); const collection = db.collection('users') app.locals.collection = collection; }) app.use('/', indexRouter);

No funciona. No se invoca la función. Si cambio el enrutador en index.js a "/movies" o cualquier otra cosa, funciona en ese enrutador, pero el enrutador doméstico predeterminado "/" no funciona. No se invoca nada. Sigo viendo el encabezado "bienvenido a expresar" del index.html.

¿Algo está sobrescribiendo este enrutador?

about 4 years ago · Juan Pablo Isaza
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!