已安装nodemon但执行Nodemon [filename.js]提示command not found求助
Hey there, let's troubleshoot this nodemon issue step by step—this is a super common problem with global npm packages, so we'll get it sorted!
Common Solutions to Try
Check if your global npm bin path is in your system PATH
First, find where npm installs global packages by running:npm config get prefixThis will return a path like
/usr/localor~/.npm-global. Thenodemonexecutable lives in thebinsubfolder of this path. Now check if thisbindirectory is in your system's PATH:echo $PATHIf you don't see the
binpath listed, you need to add it to your shell configuration file (like~/.bashrc,~/.zshrc, or~/.profile). For example, if your prefix was~/.npm-global, add this line to the file:export PATH=$PATH:~/.npm-global/binSave the file, then restart your terminal or run
source ~/.bashrc(replace with your config file name) to apply the changes.Use npx to run nodemon temporarily
If you need a quick fix without messing with PATH settings, usenpxto execute nodemon directly:npx nodemon [filename.js]npx automatically locates the installed nodemon (global or local) and runs it for you.
Reinstall nodemon with proper permissions
Sometimes global installs fail silently due to permission issues. On macOS/Linux, try reinstalling with sudo (be cautious with sudo, but it's safe for npm global packages here):sudo npm install -g nodemonIf you prefer not to use sudo, configure npm to install global packages in your user directory instead:
npm config set prefix '~/.npm-global'Then follow the first step to add the
~/.npm-global/binpath to your PATH, then runnpm install -g nodemonagain without sudo.Double-check command case sensitivity
Bash is case-sensitive! You mentioned runningNodemon [filename.js]—make sure you're using all lowercase:nodemon filename.js
内容的提问来源于stack exchange,提问作者Ryan Mcguinn

