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

138
Views
La importación dinámica no funciona en rutas expresas

Estoy tratando de implementar una importación dinámica dentro de un enrutador express.js

ahora tengo un código de abajo

HelloWorldController.js

 export const helloWorld = function (req, res) { res.send('hello world') }

enrutador.js

 export default async function (app) { app.use('/', await ( async function () { const helloWorldController = await import('./helloWorldController.js') const router: express.Router = express.Router() router .get('/', helloWorldController.helloWorld) return router }) }

servidor.js

 import express from 'express' import router from './router.js' const app = express() router(app) app.listen(3000, function(){ logger.ready(`Web Server is running on port 3000`) })

Este es el resultado que obtengo cuando ejecuto server.js

tengo un error 404

 GET / 404 18.761 ms - 25

esto esta funcionando bien

enrutador.js

 import * as helloWorldController './helloWorldController.js' export default async function (app) { app.use('/', await ( async function () { const router: express.Router = express.Router() router .get('/', helloWorldController.helloWorld) return router }) }

** ¿Qué estoy haciendo mal? **
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La sintaxis de importación ES6 aún no es compatible con el nodo js, pruebe esta sintaxis const {express} = require("express")

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!