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

1.2K
Vistas
Node TypeError: root path required

I am trying to setup a simple node/express server and I receive the following error

TypeError: root path required

I would like to know how to fix this error. Thanks


var nodeModulesDir = process.env.NODE_MODULES_DIR,

app.use(express.static(publicDir));
app.use("/node_modules", express.static(nodeModulesDir)); // ERROR AT THIS LINE
app.post("/uploads", onUpload);
app.delete("/uploads/:uuid", onDeleteFile);
about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Tryout this way

app.use(express.static(__dirname + '/public'));

i mean use __dirname for get from main root path .

about 4 years ago · Santiago Trujillo Denunciar

0

modify .bash_profile add export NODE_MODULES_DIR=GGGGGGGGGGG

enter image description here

BTW, Don't forget restart the server!

about 4 years ago · Santiago Trujillo Denunciar

0

TL;DR: check your publicDir or nodeModulesDir variables that you are passing.

Express uses the module serve-static.

so the error comes from:

function serveStatic (root, options) {
  if (!root) {
    throw new TypeError('root path required')
  }
   ...
}

serveStatic(root, options)

Create a new middleware function to serve files from within a given root directory. The file to serve will be determined by combining req.url with the provided root directory. When a file is not found, instead of sending a 404 response, this module will instead call next() to move on to the next middleware, allowing for stacking and fall-backs.

about 4 years ago · Santiago Trujillo 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