Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.2K
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda