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

485
Vistas
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 Respuestas
Responde la pregunta

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 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