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

484
Visualizações
start script not working with npm start, but works fine with node server.js

I have been stuck on an issue for quite some time and cannot seem to figure out what I am doing wrong. When I cd into my project's src folder and run node server.js everything works as expected. I am able to open the application on localhost with http://localhost:3000/client/pantry/index.html. However, when trying to make a start script in package.json I encounter some issues. My script does indeed connect to the server as I get a message in console "Server listening on port 3000" from this bit of code: app.listen(port, () => { console.log(Server listening on port ${port}); }); , but when I go to http://localhost:3000/client/pantry/index.html I receive a 404 (Not found) response and page does not load.
Here is a list of things that I have already tried:

  1. delete node modules folder and run npm install
  2. ` "scripts": {

"start": "node src/server.js"

}`

this also includes almost every combination of folder structure I can think of (i.e: "start": "node ./src/server.js", "start": "node ../src/server.js", "start": "node ./../server.js", "start": "node server.js", relative path, full path, etc.)

  1. run script from src directory with BOTH npm start and npm run start
  2. run script from project directory ("MyPantry") with BOTH npm start and npm run start
  3. reinstalling node

What I think the issue could possibly be:

  1. Something wrong with folder structure
  2. Some middleware issue that only applies with start script. I am using app.use("/client", express.static("client"));, within my server.js file that allows access to client folder on web. (once again, works fine with node server.js without start script).
    Below are pictures of folder/file structure along with 404 error, package.json, and web view with/without start script:

folder structure and 404 error

package.json file

web view with start script

without start script vvv web view running node server.js in terminal

full packag.json Any help is greatly appreciated!

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I found the solution to my problem. It was indeed the middleware used to serve the client file on the web. I had to change app.use("/client", express.static("client")); to app.use("/client", express.static("./src/client"));. Now npm start works and node src/server.js works.

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