Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

481
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!