Nodemon修改代码后触发两次重启问题求助
I’ve run into this exact annoying issue before when pairing Atom with nodemon—those duplicate logs make it impossible to track what’s actually happening. Let’s walk through the most reliable fixes to get rid of that double restart:
1. Disable Atom’s Safe Save Feature
Atom has a default "Safe Save" setting that creates a temporary file first, then replaces your original file. Nodemon detects both the temp file creation and the original file update, triggering two restarts in a row. Here’s how to turn it off:
- Open Atom’s Settings (press
Ctrl+,or go to File > Settings) - Search for "Safe Save" in the top search bar
- Uncheck the box next to "Enable Safe Save"
2. Tell Nodemon to Ignore Editor Temp Files
Atom generates hidden temporary/swap files when you edit, and nodemon might be picking those up as "changes." Create a nodemon.json file in your project root to exclude these files:
{ "ignore": [ ".git", "node_modules", "*.swp", "*.tmp", ".atom/**" ] }
Or add the ignore flags directly to your package.json script if you prefer:
"scripts": { "dev": "nodemon --ignore '*.swp' --ignore '*.tmp' app.js" }
3. Update Nodemon to the Latest Version
Occasionally, double-restart bugs get patched in newer nodemon releases. Run one of these commands to update:
# Update global nodemon npm install -g nodemon # Update local project nodemon npm install nodemon --save-dev
4. Test with Manual Saves First
If you have Atom’s auto-save enabled, try turning it off temporarily and saving changes manually (Ctrl+S). Auto-save can sometimes trigger multiple file change events that nodemon misinterprets as separate updates.
After trying these steps, make a small code tweak and save—you should only see one [nodemon] starting node app.js line followed by your single "Connected to db..." log.
内容的提问来源于stack exchange,提问作者Raz

