command not found: nodemon --- need helping adding directory to PATH - node.js

I have looked at a lot of answers on here and I'm still not able to figure this one out. I am attempting to learn node again, but after my global install of nodemon (which completed successfully) I am getting command not found: nodemon when running nodemon app.js. A while back I moved my npm path to /Users/mlefkowi/npm-global for some reason. When I echo $PATH, that directory does not exists. This is what I get:
/Library/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I have been able to add it to the $PATH, but when I close out Terminal it doesn't save. Should I move npm back to it's default directory? How can I get a path to save to $PATH?

Edit your ~/.bashrc and add the following line:
export PATH="/Users/mlefkowi/npm-global:$PATH"
This assumes that /Users/mlefkowi/npm-global/nodemon is the path to the nodemon executable. If it's in a bin sub-directory off of npm-global, then change /Users/mlefkowi/npm-global to /Users/mlefkowi/npm-global/bin.
.bashrc is sourced every time your shell starts up, so this modification will stick for all new terminal sessions. After editing it for the first time, run source ~/.bashrc to update your PATH for that session.

Related

Node.Js windows command prompt change C:\ path to test directory instead

I'm trying to figure out if there is a way to change the Node.Js command prompt default path = C:\users...> (default when the prompt is launched) or C:\Windows\System (if launched with administrator privileges), to the location of the folder where i'm working.
Normally I have been doing C:\users..> cd C:\xampp\htdocs..... to navigate to the test folder and run test. Although once the command prompt is closed it reverts back to C:\users...>.
To achieve what I want I came across using Z:>C:\xampp\htdocs\projects.... but this returns access denied with or without administrator privileges. Even if I try C:>C:\xampp\htdocs\projects.... still get the Access Denied for some unknown reason. To be honest I don't know what Z:> or C:> will result.
Is it possible to change the default prompt path to the path of the directory I am working in so that every time command prompt is launched it goes to that directory? In this case C:\xampp\htdocs\projects.... instead of C:\users...>
This seems like a general windows CMD question. Simply change the start up directory for CMD. See this SO post.
Once you're in that directory, you should be able to run the node command as normal.
Look inside your default nodejs installation folder for a file called nodevars.bat. Here is my path:
C:\Program Files\nodejs\nodevars.bat
Open this and look towards the bottom--the line I needed was on the very bottom. Here is the line from the git master:
if "%CD%\"=="%~dp0" cd /d "%HOMEDRIVE%%HOMEPATH%"
I changed mine to
if "%CD%\"=="%~dp0" cd /d "C:\Users\David\Desktop\work\J\math"
And now I am happier.
I had the same question, today, 4/11/22, and DuckDuckGo provided this as the number one result for my query. Since the question appears to be unanswered, I will try for those who might show up later.

Node: Can I run global modules/packages from command line without specifying full path [Ubuntu, Nodejs, NPM]

I'm a linux / ubuntu / node newbie. I am running ubuntu 16.04 on a virtual private web server. It's running nodejs & everything is running well.
But when I run a global module/package from the command line, I write it like so:
node /usr/local/bin/forever start /usr/local/bin/http-server /var/www/myWebsite -p 8000
Which works fine. But you'll notice in node I have to specify the full path to my globally installed module/package (/usr/local/bin/)
My question: Is there a way I can run a global node module/package without specifying the full path?
EG., instead of writing:
node /usr/local/bin/forever // forever is a globally installed module
Can I make it so I can write:
node forever // forever is a globally installed module
I have tried editing my ~./bashrc file to include a NODE_PATH like so
nano ~/.bashrc
# added line at bottom of bashrc file
NODE_PATH=/usr/local/bin
But no luck. Also, when I run echo $NODE_PATHI get:
/usr/local/bin
Which is the correct path (as in I use that path for commands such as node /usr/local/bin/forever
Or have I got my wires crossed? Am I even supposed to be able to run a node module/package without specifying the full path? Is there any reason why it's not good practice to do so?
Many thanks.
I am so silly - editing the .bashrc file did seem to work. (Actually I'm not sure if this did work, or if it was automatically set correctly the whole time)
What I didn't realise is that I needed to:
Restart the terminal
Run a global package with just it's name (no "node" prefix)
EG in ubuntu cmd line:
node forever -h // WRONG!
forever -h // Works!
Thought I'd post in case someone in a similar situation finds this.

'express' command not found on mac

Definitely a noob question so please don't judge but this has been bothering me for a while.
No more how many times I run $ sudo npm install -g express-generator or $ npm install express -g, everything seems to install but the command $ express still doesn't exist.
I'm running fish shell. Also, I'm assuming this is an issue coming from my PATH file, but I'm lost on if that's .bash_profile or .bashrc.
My .bash_profile has the three lines in it:
export PATH=/usr/local/bin:$PATH
export PATH=/Users/username/.node/lib/node_modules/express-generator/bin/express:$PATH
export PATH=/Users/username/.node/bin/express:$PATH
and my .bashrc file has nothing regarding node in it.
When express installs, it returns:
/Users/username/.node/bin/express -> /Users/username/.node/lib/node_modules/express-generator/bin/express
/Users/username/.node/lib
but when I command which node it returns
/usr/local/bin/
When I try to run $ls -l /usr/local/bin/express it returns:
ls: /usr/local/bin/express: No such file or directory
Cannot find the diagnosis of why the express command won't work after installation.
If you are running fish, your .bash_profile is ignored, of course!
The preferred way to add /Users/username/.node/bin/ to your $PATH in fish is like so:
set -U fish_user_paths $fish_user_paths /Users/username/.node/bin/
that's just something you run once, at the command line - not something you put in a startup file.
If you prefer to use startup files, you can instead modify your ~/.config/fish/config.fish like so:
set PATH $PATH /Users/username/.node/bin/
From the symlink after the install, the express binary should be available in the /Users/username/.node/bin directory. The reason you can't use the binary is because the /Users/username/.node/bin directory is not in your $PATH. Whats in the $PATH is the binary itself.
When you add a directory to your $PATH, you can execute binaries from within the directory. Currently, your $PATH points to the /Users/username/.node/bin/express which does not have any binaries within it. You should correct it to:
export PATH=/Users/username/.node/bin:$PATH

NodeJS Error: node.js:810 var cwd = process.cwd();

I'm new to nodeJS and also new to StackOverflow...
I'm starting to develop my first SPA, using RequireJS to compile my sources into a "dist" folder. I had NodeJS running a basic script to run my server:
var connect = require('connect');
connect.createServer(
connect.static(__dirname)
).listen(8080);
Everything was working well, till I compile my src again. That replaced all the files served by my server, so I though I would restart Node. I Ctrl^C and from this moment, I can't get Node to start again. When I try to run:
olivier$ node server.js
I get this error:
node.js:810
var cwd = process.cwd();
^
Error: ENOENT, no such file or directory
at Function.startup.resolveArgv0 (node.js:810:23)
at startup (node.js:58:13)
at node.js:901:3
What's strange is that I get the same error just trying to start NodeJS, simply doing:
olivier$node
Anyone has an idea of what I can do beside uninstalling Node and reinstalling it ?
I got this when trying to run the Node REPL from a directory I had already deleted (from another shell). Don't let this happen to you or you will be ashamed.
Could it be that RequireJS is also recreating the directory that contains your server.js?
Try and see if this works:
$ cd $PWD; node server.js
Although it seems useless to change the directory to the current directory, the rationale is that when a directory gets deleted while it's the current working directory of your shell, the shell is left in a dangling state because it's still 'attached' to the previously deleted directory. This also affects any processes that you start from that shell (like Node), and can yield confusing errors.
By executing cd $PWD, you make sure your shell gets 'reattached' to the newly created version of the directory, solving the dangling state.
use
cd .
is ok.
But the problem is in server
Remove the folder in another terminal and save its the file,
Open the new terminal on folder structure, and run the file.
Folder structure was not available on the current terminal session. When you close it and re-open the terminal in your file directory, the structure will be refreshed.
I faced the same issue.
To Solve this issue enter below command :
cd ..
OR
Check your directory in Terminal/CMD. and Change it.
Actually this issue coming when you deleted your project folder form your PC and without change directory try to run any command of React-Native.
I faced the same kind of a problem when starting the app in cluster mode via pm2.
I did the following & it worked,
* executed pm2 kill
* Removed node_modules
* npm install
* start the application
Reference: https://github.com/Unitech/pm2/issues/1244
Then it started to work as expected. Hope it helps.
If we try to do any actions on an already deleted file from another shell then we'll face this issue.
Just restart the system it'll work normally ( It worked for me )
I would suggest to close all the terminals and run below commands
sudo npm cache clean -f
sudo npm install -g n
and voila: no more process.cwd problems

Grunt on Windows 8: 'grunt' is not recognized

I'm having a problem running Grunt from the command line on my Windows 8 machine.
My research indicates the most common solution is to install grunt-cli, since Grunt is no longer global. I also need to make sure I actually install the Grunt task runner, since that's not installed with grunt-cli.
Other solutions point to the PATH system environment variable, but that appears to be pointed as I'd expect to:
C:\Users[username]\AppData\Roaming\npm
Having done all that, I'm still getting a "'grunt' is not recognized as an internal or external command, operable program or batch file" error message in the CLI. I've tried the following things, uninstalling everything after every attempt:
Installed grunt-cli globally (npm install -g grunt-cli), then grunt at the directory level I want to use it (npm install grunt)
The same as above, but with the order of installation reversed
The same as both of the above, but using the Admin Command Prompt
Am I missing something obvious?
I've not had any issues with grunt on several different windows 8 machines.
If you open the folder: C:\Users\[username]\AppData\Roaming\npm
Do you have a file named grunt.cmd in this folder?
If not I'd maybe try npm install -g grunt-cli again, maybe from an elevated command prompt.
If this exists and you have C:\Users\[username]\AppData\Roaming\npm in your PATH environment variable then typing grunt from a command prompt should work.
Silly question, have you tried closing the command prompt and opening a new one?
Confirm your PATH is correct (and not messed up). Just type PATH from the command prompt. There's really no other explanation that makes sense given the error you're describing and the steps you've taken.
Normally, using the where grunt command would have found grunt.cmd in your path if npm is installed correctly and it has been properly added to the system path.
Close all Command Prompt instances.
Start a new Command Prompt instance.
Type PATH Enter and verify if C:\Users\Username\AppData\Roaming\npm is part of the path.
If not, you need to log off and on again,or close the Command Prompt and restart the explorer process.
In the Command Prompt, type where grunt Enter.
You're good if it reports:
C:\Users\Username\AppData\Roaming\npm\grunt
C:\Users\Username\AppData\Roaming\npm\grunt.cmd
Otherwise, you have to reinstall the grunt-cli package if it reports:
INFO: Could not find files for the given pattern(s).
Apparently, programs that change the PATH environment variable must broadcast a WM_SETTINGCHANGE message. The Windows' System settings window does it correctly when you change the PATH variable, but the NPM installer doesn't. That's why you have to restart explorer (or log off or restart, which has the same effect).
I know this has been answered but I thought I'd offer my step by step solution for windows 8.
First thing I checked was the PATH in my laptops Environment Variables (Right click my computer > properties > advanced system settings > Environment Variables)
It wasn't listed in there so I added a new variable in User variables (so it was specific only to my user account)
In the new user variable prompt I entered the following;
Variable Name: PATH
Variable Value: %USERPROFILE%\AppData\Roaming\npm
Quit command prompt, repoened, navigated to my projects directory and tried running grunt again and... SUCCESS!
I had the same issue.
I tried different things:
Restart computer
Deleted the grunt folder and ran
npm install -g grunt -cli
Didn't work.
Finally tried:
npm install -g grunt-cli
Worked perfectly.
Tried
where grunt
and I saw 2 locations where it was found.
I was facing the same problem on windows 8
I have added ' %APPDATA%\npm ' to the path variable . It has been working fine.
some times NPM install corrupts the basic windows path. i usually have a copy of my own version of PATH mainted separately. every week or on some installs i manually configure and update the %PATH% variable.
Basically Grunt.cmd is not availbe through %PATH% variable.
I have stucked with problem on Windows 8, that after install grunt-cli I've always got "command not found" while I'm tried to check grunt -v or where grunt. So I've added to enviroment PATH this path C:\Program Files (x86)\Git\local and run grunt.cmd from that folder (you need to look in node_modules folder here). And after reloading my terminal everything started to work.
Same happened to me and here was the solution:
Have you got 2 different versions of Node.JS installed?
Maybe Nodist?
This means you likely got NPM installed twice which will install the commands into 2 different folders:
Once into C:\Users\<user>\AppData\Roaming\npm and once into C:\dev\nodist\bin\bin.
C:\dev\nodist\bin\bin wasn't on my path variable so I added it, and I removed the Node.JS version I didn't want to use.
If you have no grunt.cmd file created by npm, make sure that you do not have a .npmrc in your home directory with: bin-links=false in it.
After getting a tonne of "'grunt' is not recognized as an internal or external command," errors, I solved this on Windows 10 by going to Path and adding C:\Users\Username\AppData\Roaming\npm

Resources