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

174
Vistas
how to convert the following syntax into an es6 syntax?

I have this statement to modularize my express.js api's:

app.use("/api/users", require("./routes/api/users"));

How to write it using import statement?

inside "./routes/api/users", I am exporting express.Router()

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Inside users.js use const router = express.Router() and then export default router At the top of your file write import router from "./routes/api/users"

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use default export of es6 in "./routes/api/users" as well although it's not compulsory.

./routes/api/users


import { Router } from "express";

const router = Router();

router.get("/", (req, res)=> {
    // 
});

export default router;

And then import it using the following syntax.

import UserRoutes from "./routes/api/users";
about 4 years ago · Juan Pablo Isaza Denunciar

0

I guess you are using node JS. So, basically nodeJS uses CommonJS by default, so you are using require() statement which is a part of CommonJS. To use the latest ES6 import export feature, go to package.json and add the following inside of the JSON container:

    "type": "module",

Note that this must be in the first object, not nested inside of anything. You can write it below the version ( for ease of understanding ).

Hope it helps

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