MEAN项目中Node/Git Bash启动服务器路径异常:Bug还是用户误操作?
Hey Emma, let's get to the bottom of these path-related errors you're seeing when firing up your server with Node and nodemon!
What's Causing the Issue?
From your description, the root problem boils down to incorrect path targeting in your startup commands:
- When using Node directly, you aren't specifying the
src/directory, so it’s hunting forapp.jsin your project root (trainingapp) instead of the correcttrainingapp/src/location. - With nodemon, there’s a path formatting glitch where the backslash between
trainingappandsrcgot dropped—turningtrainingapp\srcintotrainingapprc(hence the missing\syou noticed).
Step-by-Step Solutions
1. First, Confirm You’re in the Right Directory
Before running any commands, make sure you’re working from your project’s main folder (trainingapp) in Git Bash:
- Check your current directory with:
pwd - If you’re not in
C:\Users\Emma\desktop\trainingapp, switch to it using:cd C:\Users\Emma\desktop\trainingapp
2. Correct Commands to Start the Server
Using Node directly: Run this command to target the proper
src/app.jsfile:node src/app.jsThis tells Node to look inside the
srcsubfolder for your entry file, instead of searching the root directory.Using nodemon: Use the same path structure to fix the typo issue:
nodemon src/app.jsThis will watch
src/app.jsand auto-restart the server when you make code changes.
3. Set Up npm Scripts for Easier Startup (Recommended)
To avoid typing full paths every time, add scripts to your project’s package.json file. Open package.json and update the scripts section like this:
"scripts": { "start": "node src/app.js", "dev": "nodemon src/app.js" }
Now you can start the server with simple commands:
- For production mode (Node only):
npm start - For development mode (nodemon auto-restarts):
npm run dev
4. Double-Check File Location
Just to be thorough, verify that app.js actually exists at the correct path:
ls src/
You should see app.js listed in the output. If not, double-check that you placed the file in the src folder of your trainingapp project.
内容的提问来源于stack exchange,提问作者Emma Ryan

