(Windows) How to fix nodemon | Node.js - node.js

So I started using nodemon a while ago and started to use it again recently. But I got an error from the VS-Code command line:
The term 'nodemon' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ nodemon
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (nodemon:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
This basically means it isn't a command, similar thing would happen in an actual cmd.
Edit: I made this Q&A just for some people who have this same problem.

If you get this error, this probably means you either haven't installed nodemon, or it is not on your environment variable called 'Path'. I am assuming you did do npm install -g nodemon. Otherwise I have no idea what you are doing here. Also, this will be a very in-depth answer
So first, you want to go to your search bar in Windows. Then type; "env".
After, you want to click on "Edit the system environment variables". It's self-explanatory, it's the system environment's variables.
Then, you want to click on "Environment Variables." A window will pop up with a lot of things, you want to find the variable called 'Path' in the system variables:
You then want to select it and click "Edit". Then a tab will open up; with the contents of the variable, I am using version 10.0.18363 of Windows, yours might look different then mine. But you want to add a new variable. If you have this variable C:\Users\yourUsername\AppData\Roaming\npm and nodemon still doesn't work, you can skip this step. Otherwise you will see other paths listed, just append to it separating with semicolon.
For example, let's say the last path listed is, "C:\Windows\System32". I would add a ";", and then the path to nodemon, so the final result will look like: "C:\Windows\System32;C:\Users\dawoo\AppData\Roaming\npm".
After that, you want to click OK and then OK again. You should be fine now. If you still have the problem, like I did, you want to right-click on the Windows button, and click: "Windows PowerShell (Admin)". You want to copy and paste three things seperately. I pressed "A" for 1 and 2 (Yes to All), this might not work, so try "Yes", which is "Y".
) Set-ExecutionPolicy RemoteSigned
) Set-ExecutionPolicy Unrestricted
) Get-ExecutionPolicy
After you type Get-ExecutionPolicy, you should get "Unrestricted" or "RemoteSigned", something like that. Now, nodemon should work now! I just wanted to make this Q&A post because I saw lots of people DMing me on Discord saying nodemon doesn't work, and I also wanted to help others who stumbled across this problem. Have a great rest of your day.
Edit: OverFlow didn't save my changes, hopefully you see this but I found out how to fix this problem from one of my friends.

Related

node command returns nothing in Command Prompt (Windows 10)

Lately, I was trying to install NodeJs on my desktop PC and I ran into this weird problem. When I type, eg. node -v command, it returns nothing. After node I can add anything, it will just be ignored and won't return anything in the next line. I've added C:\Program Files\nodejs to PATH system variable, but it still doesn't work. Only time node -v command works is when I do (in cmd) C:\Program Files\nodejs>cd C:\Program Files\nodejs, then C:\Program Files\nodejs>node -v and in the next line it returns proper verision v16.13.1 .
Obviously, node command works and returns properly only when I run command from \nodejs folder, but as I saw on the Internet, it should work (with system PATH set up) from any folder. I think something is messed up in my Environment Variables, but if you know how to solve this problem, please let me know! Every comment is appreciated!
I downloaded NodeJs from https://nodejs.org/en/download/ (LTS, Windows Installer, 64-bit). Thanks in advance!
PS. npm command works correctly from any folder.
#Compo
Your issue is that you have many things in the %Path%, and clearly have made errors when adding for node.exe.
The first noted problem is that you have added C:\Program Files\nodejs\node.exe when you should have used only C:\Program Files\nodejs. Entries in this variable are for the directories which hold your executable files, not the files themselves. However, as C:\Program Files\nodejs is already included, you can simply remove that invalid entry.
The next issue, is that you need to understand what happens when you enter node in the Command Prompt or a batch file. What happens is that the current directory is searched for files named node which have an extension matching one listed in the %PATHEXT% value, (which is searched in order first to last). If a match is found, that file is run, and the searching stops. If no file is found, the same process occurs with every location listed under %Path%, (in its listing order first to last), the first matching file is run and the searching stops.
So by using node, what happens in your case is the %Path% is being searched, because there is no file named node.COM, node.EXE, node.BAT, node.CMD, node.VBS, node.VBE, node.JS, node.JSE, node.WSF, node.WSH, or node.MSC in the current directory. So each location is searched in order, until it reaches the first match, which in your case happens to be C:\xampp\htdocs\WebRulet\node.JS.
So essentially by using a presumptive/lazy command you are effectively running:
C:\xampp\htdocs\WebRulet\node.JS -v
Which is not what you wanted, and why you are not getting the result you had hoped for.
So now you understand the process which happens, by using code which make assumptions, and how that could cause issues, errors, or potential catastrophies. You should realize with all of that searching, especially if you have many entries in your %Path% and/or %PATHEXT% values, that the quickest and safest way to run your command would be:
"C:\Program Files\nodejs\node.exe" -v
Or
"%ProgramFiles%\nodejs\node.exe" -v
Please note that those absolute paths are double-quoted because they contain space characters. However, spaces are not the only problematic characters used in filenames, so best practice is, unless you are certain there are no such poison characters, to always double-quotes.
Now I know that almost every site will never explain all of that information, and all the code you read will not follow it either, so you are probably going to want to minimize your typing whilst working on the command line.
In order to do that, you will need to ensure that your %Path% value string, is ordered in such a way as your most frequently typed executable file path, is nearer the beginning, than any other location holding a possible matching file. However I will strongly suggest that you always use file extensions, for safety, (it is, after all, usually just four more characters to type).
Noting the entries in your %Path%, there are some extremely important ones missing, which means that your %Path% is essentially corrupted, and requires fixing because it will seriously affect the proper running of your Operating System.
To fix your variables, and order them correctly, begin by typing the following in your Command Prompt window:
Start %SystemRoot%\System32\SystemPropertiesAdvanced.exe
In the window which opens, click on the [Environment Variables] button. A new window will open, within the User variables (upper pane), double-click on Path, and using the [New] [Delete], [Move Up] and [Move Down] buttons make sure that the entries in it, in this order, are:
%UserProfile%\AppData\Roaming\npm
%UserProfile%\.dotnet\tools
%UserProfile%\AppData\Local\Microsoft\WindowsApps
%UserProfile%\AppData\Roaming\Composer\vendor\bin
D:\Inkscape\bin
Once done, click on [OK] to close the window, then do the same thing for System variables, (lower pane), with the following ordered list:
%SystemRoot%\System32
%SystemRoot%
%SystemRoot%\System32\wbem
%SystemRoot%\System32\WindowsPowerShell\v1.0
%SystemRoot%\System32\OpenSSH
%ProgramData%\ComposerSetup\bin
%ProgramData%\DockerDesktop\version-bin
%ProgramFiles%\Docker\Docker\resources\bin
%ProgramFiles%\Azure Data Studio\bin
%ProgramFiles%\nodejs
%ProgramFiles%\dotnet
%ProgramFiles%\heroku\bin
%ProgramFiles%\Oracle\VirtualBox
%ProgramFiles%\NVIDIA Corporation\NVIDIA NvDLISR
%ProgramFiles(x86)%\NVIDIA Corporation\PhysX\Common
%SystemDrive%\xampp\bin
%SystemDrive%\xampp\htdocs\WebRulet
Once complete click on [OK], [OK], and [OK] to close your windows, and then close the Command Prompt window.
From now on you should be able to open any new Command Prompt window and use:
node -v
But remember, I strongly advise that you get into the habit of using its extension:
node.exe -v
Which should result in:
v16.13.1

How to run NodeJS CLI tools without having to type npx

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).

"npm" is not recognized

So, I am trying to use command prompt for something. But it isn't working.
The steps were, get Node.js. Download a dropbox file of what I need. Copy the path thing that I use to get to the file in File Explorer.
Turn on Command Prompt type in "cd C:\Users\Evan\Desktop\GoAniFire-master_10.zip" and it worked.
I have Node installed, but then when i type in "npm install" after i hit enter on the last step. Nothing besides a error saying "npm isn't recognized" pops up, I have no idea what to do as I am new to Node.js and only recently started using command prompt. ;-;'
-Nate
If you installed Node from the official site, you should already have the Node Package Manager. You're likely receiving this error because Node isn't in your Path, so your command prompt doesn't know what it's looking for.
Open Control Panel -> System and Security -> System -> Advanced System Settings -> Environment Variables
In "User variables" or "System variables" find the variable Path. (If it doesn't exist, create it.)
Add your node.js folder path at the end of the variable value, beginning with a semicolon separating it from previous values. e.g. ;C:\Program Files\nodejs
Restart your command prompt.
This should work.
Make sure you installed node. Try restarting your computer first. If that doesn't work follow what user Elo wrote.
Open Control Panel -> System and Security -> System -> Advanced
System Settings -> Environment Variables
In User variables find variable PATH and add path to nodejs. Usually
-> C:\Program Files\nodejs;. If variable doesn't exists, create it.
Restart PC and IDE.
If you're using VSCode, close old terminal and open a new one. Even
when I did everything VSCode could not see node + npm, because old
terminal was broken.

The term 'node' is not recognized as the name of a cmdlet, function, script file, or operable program [duplicate]

This question already has answers here:
The term 'node' is not recognized... In Powershell
(11 answers)
Closed 6 months ago.
I'm getting this error while running node in my VS Code terminal besides I tried to run the same thing in CMD and it worked there but not in VS Code terminal:
node: The term 'node' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ node
+ ~~~~
+ CategoryInfo : ObjectNotFound: (node:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
What worked for me was : open Visual Studio Code -> Terminal -> New Terminal
Everything else I tried didn't...
I also got this error, I resolved it by opening Visual Studio Code with Run as administrator privilages (in Windows).
Try closing and then reopening VS Code.
If you have installed node while VS Code was opened then the change to the PATH won't be visible yet. (be sure that the add to PATH option is selected while installing node...if not be sure to add it to the PATH)
I faced the same error. And the solution I found is while reinstalling on the last step it asked if we wanted to install Choclatey and other few files that may be required, I unticked that option and Whola it worked. I dont know the technicality why it worked but it worked.
if you have anaconda installed, everytime vscode the terminal, infact the vscode opens the conda environment,
you can solve it by typing,
conda install -c conda-forge nodejs
I faced the same problem, it's because I select an option to install chocolatey and python during installation process .
When I try to uninstall my node installed and try to reinstall without choosing option to install chocolatey and python it works for me ....
enter image description here
Add node to your environment variable using following steps.
If your operating system is windows 10,
Right click "This PC" -> Properties
Properties
Then click "Advance system settings" and click "Environment Variable" button as follow
Environment variable
Then select the path and click Edit button
User Variables for Administrator
For the above error you have to add node js location.
Click New and add node file path.
C:\Program Files\nodejs
File path

How to work with directories in Gulp?

I was following this tutorial. The writer mentions that I need to install node.js which I did. It is installed in
C:\users\me\AppData\Roaming\npm
After that the writer says I need to create a folder called project which I did. The folder is here
C:\users\me\project
Next the writer says that I need to
Run the npm init command from inside that directory.
which I don't understand. When I start command prompt as administrator I get
C:\Windows\System32>
when I run it without administrator, I get
C:\users\me>
How do I go inside my project directory then?
I have never used Gulp before and only once or twice used command prompt. I have been searching for a few hours now but I could not find anything. Maybe I am using the wrong search terms. Any help would be appreciated.
Why was it downvoted? If I could find the answer I swear I would not have posted this question and I clearly mentioned that I am a beginner.
First off your problem has nothing to do with gulp specifically. You're not "working with directories in Gulp" as your title puts it. You're just working with directories in the Windows commmand prompt (cmd).
You should probably read a tutorial on how to use cmd first, before using a command line tool like gulp. Here's one for example.
To answer your question: open cmd as a non-admin user. You're now in the \users\me directory. Type:
cd project
You're now in the \users\me\project directory and can issue the npm init command.

Resources