I was messing around with the npm package today and I noticed that all of my commands were being run from my command prompt on my machine rather than through the node.js command line that comes with the download.
Bottom line: Why is there a node command prompt if you run commands from your local command prompt?
I saw there was a question like this here: node.js command line tool but it doesnt exactly answer the question.
I appreciate any help out there.
The node.js command prompt has your node.js environment set-up. Most of time, if you try to install some global package through your local command prompt, it will not work as expected, but if you use node.js command prompt it will. Happened to me while trying to use the express-generator.
Related
TL;DR
I cannot execute commands such as tsc unless I include npx before it (e.g npx tsc). How can I fix this?
The title is a bad explanation of the problem I have.
Say I have installed an npm package with a CLI with it (typescript in this example). And the CLI is used like
tsc <filename> or just tsc. But whenever I try to do it like that, I get an error like
'tsc' is not recognized as an internal or external command,
operable program or batch file.
But... when I do
npx tsc
then it works!
So whats the problem?
The problem with doing npx tsc is because
npx is slow at executing commands
its annoying having to type npx and the front of every command.
And the thing is, this was originally not a problem with WSL.
Why dont you just use WSL?
I have always had problems with WSL (primarily permission issues due to security reasons) and so I uninstalled WSL and just used command prompt. I would have perferred using WSL but it was simply not an option.
Other Info:
I am using Windows command prompt.
I have installed the packages globally
So is there a way to just execute commands that way or is it Command prompts fault?
! this only works for Windows !
Ok, so I came across this post and thankfully, the first answer there was the solution!
Just add %USERPROFILE%\AppData\Roaming\npm to the path variable in system variables!
To access the system variables, press the Windows key, type Environment variables and click on Environment variables at the bottom of the window. The path variable can be found under User variables for (profile name).
I installed Truffle, the Ethereum development toolkit, on my Ubuntu 14.04 PC. I can execute it easily from a terminal window by simply typing "truffle". However, when I try to execute Truffle from a Bash shell script, I get the following error:
ide-do-truffle.sh: line 3: truffle: command not found
The line inside the shell script is just:
truffle compile --network local
How can I execute Truffle from within a shell script?
If someone can also explain what goes on behind the scenes when you execute a globally installed Node.JS package like Truffle, that would be helpful too.
Its possible the PATH in your terminal window is not the same as the PATH that your shell script sees.
Try echo "$PATH" in both your terminal window and in your script just before your truffle line in your script, and compare the two. If there is a difference, then the problem is with the PATH in your shell script.
I have Node.js + NPM installed; I can run node -v in my console and get back the current version.
I have also tried using NVM Windows as a Node.js version manager and can run both node -v and npm -v there as well.
HOWEVER, when trying to use another framework like Gulp or Ionic or whatever, I keep getting the error:
'node' is not recognized as an internal or external command,
operable program or batch file.
node is obviously a cmdlet as I can run node -v.. but somehow my other frameworks are no longer able to find it.
Path is correct and everything looks good.
What am I missing here?
The program ConEmu for windows terminal management wasn't pulling or allowing programs to access the paths through subcalls or something it seems. I tested with CMD and Powershell respectively and both worked as expected.
I couldn't get ConEmu to seemingly pass these path to subroutines.. so I uninstalled it and found an alternative called Cmder that is built on ConEmu and it was able to pick them up just fine.
I don't know specifically if it was just a setting in ConEmu I couldn't find or if I needed to manually add these--but happy knowing Cmder just does it automatically.
I installed the .msi file from nodejs website and installed it.
Now, when I run nodejs.exe, I do get a command prompt, but it shows a blinking > by default, instead of C:/>
It looks somewhat like this:
What to do?
This is called the REPL. You can enter statements for Node to execute and get realtime feedback. Ctrl+C twice will get you back to the command prompt.
I recommend checking out the answers to How do I get started with Node.js for learning more about Node.js and how it works. Typically you provide a file with your Javascript for Node to execute:
node app.js
or you can leave the .js off:
node app
I have a question about usage of Nodejs.
I installed it on Win7 and run (green Node.js icon) it, but when I tried to run "npm install" command it dodn't work. I had to move to Nodejs command prompt where npm is working.
Is that how it supposed to work?
Once you install NodeJS under Windows, it goes into the global PATH, meaning that it is available in the usual Windows command prompt. So, just open one by pressing:
Windows+R
Type cmd and press Enter
Then type node -v. You should be able to see an appropriate response.
Add your AppData\Roaming\npm and Program Files\nodejs folder to your path.
Also have a look at this:
Node.js doesn't recognize system path?
Second answer helped me to add my Roaming folder.