Node.js - "which node" returns wrong path - node.js

I was messing around with my node.js config, following a guide on moving the globals folder to somewhere more appropriate.
I eventually wound up in a position where I couldn't install anything with NPM. So I tried "which npm". This returns:
"which npm"
The file path is wrong, my the C:\ drive is not being entered properly. Obviously, this is wrong. But I couldn't figure out how to change this. Out of curiosity, I tried "which node":
"which node"
Which is also wrong. I can't edit the prefix file because npm won't let me do anything. I've tried PC restarts, complete uninstalls, adding the real folder path to the $PATH but nothing is working.
Would appreciate some help!

To fix this, I delete the .npmrc file in the home directory (windows: C:\user\username), uninstalled and re-installed node.
Things are working fine now.

Related

Problems with adding flutter to my PATH in ubuntu

I tried installing Android Studio and Flutter on the PC. I followed some tutorials for the paths and I did a great many things. I am rather confused how many completely different approaches there are editing different files and commands to change the path permanently. I got it to work in theory even, if I enter echo $PATH I get
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:home/dev/flutter/bin:/snap/bin
Now, i do not know if I put the path in correctly, but it is the path that correctly leads to my flutter bin folder. I am not sure if I am supposed to crop it or anything. If i open a terminal in this directory, and enter 'flutter' i get 'flutter: command not found', while ./flutter or ./flutter doctor do what i would like to happen in any terminal but also without the ./
So, apparently flutter is installed and works, but the path is what is giving me the biggest headache. Any ideas what i could have done wrong? I really tried everything the dart docs told me to do and followed many other tutorials to no avail.

strange npm problem, command never finishes, hangs forever

This is windows 10, node-v10.15.3-x64.msi install.
using either command prompt or power shell I type npm and nothing happens and it doesn't bomb or returns to the prompt. Just the little blinking dot that lies to me saying it is doing something. When I stop being fascinated by this blinking dot and hit control c it says Terminate batch job (y/n) ? y gives me back my prompt. Obviously there was some process running but I am not getting a functioning program. Any ideas? I know this is the head scratch kind of problem that does not usually get answered but I can't be so special nobody else has this happen.
What underlying tech does npm rely on? python?
Ok with help from the other thread I got it figured out.
Yes I screwed with prefix to my detriment. The reason why I kept going round and round deleting and reinstalling is I missed .npmrc in my user directory. The prefix in it was set to a path that no longer existed. I deleted my profile .npmrc and it started working again. I have now learned that is the file to edit to set prefix and cache.
Now the structure of the nodejs stock install for npm is bizarre imho. The npm executables are in the nodejs directory. Node itself is installed nodejs/node_modules/npm. The npm modules are path nodejs/node_modules/npm/node_modules.
Initially I changed my personal .npmrc to this contents
prefix="C:\Program Files\nodejs\node_modules\npm"
cache="C:\Program Files\nodejs\node_modules\npm"
This stopped npm from installing into my appdata/roaming directory but it kept bombing because it could not create the cache directories because it was in Program Files
But I was happy because it was trying to install global into one directory instead of my profile roaming. The main reason I started this odyssey is I wanted global modules in ONE location.
So what I did was moving nodejs from program files to another directory.
change my profile .npmrc to this
prefix="C:\nodejs\node_modules\npm"
cache="C:\nodejs\node_modules\npm"
changed the path entry for nodejs in paths in system properties / advanced / environmental variables / system variables / path to C:\nodejs.
I also keep deleting path in the top path in user variables but it seems to keep coming back like Freddy Krueger. Doesn't seem to do any harm now though.
A lot of examples try to set prefix to nodejs\npm. Maybe that was kosher at one time but now the npm executable called npm is in the nodejs root directory.
Okay I am not a tech writer but I hope this will provide clues to other clueless like me. Cheers!

I really messed up NPM

I think I really screwed up npm. So I tried to get gulp to work and it wasn't so I tried changing the route but by mistake I guess the article I was looking at was for mac and I have windows. Anyways I tried to do a solution and it was still working slightly at the time, so I opened up npm config edit and a file came up to change the prefix but when I did it, I accidentally just copied and pasted instead of putting my actually computer username and now npm wont work at all or even load anything and I am trying to relocate the file but I cant use npm now and I cant find the file.
I was using this to help me out npm - EPERM: operation not permitted on Windows
Found the answer.
You want to go to thisPC -> C: -> users -> \your computers username\ -> npmrc (NPM RC file), go into that file, go to prefix= (kind of at the top) and then fix the path. Thanks everyone!
Just uninstall and reinstall node entirely. It will be faster than attempting to fix this problem.

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.

Installing Node.js (and npm) on Windows 10

I had some issues trying to install Node on Windows 10 and found the solution.
The error was as follows:
C:\Users\Stephan>npm
Error: ENOENT, stat 'C:\Users\Stephan\AppData\Roaming\npm'
The solution is below.
Edit:
It seems like new installers do not have this problem anymore, see this answer by Parag Meshram as my answer is likely obsolete now.
Original answer:
Follow these steps, closely:
http://nodejs.org/download/ download the 64 bits version, 32 is for hipsters
Install it anywhere you want, by default: C:\Program Files\nodejs
Control Panel -> System -> Advanced system settings -> Environment Variables
Select PATH and choose to edit it.
If the PATH variable is empty, change it to this: C:\Users\{YOUR USERNAME HERE}\AppData\Roaming\npm;C:\Program Files\nodejs
If the PATH variable already contains C:\Users\{YOUR USERNAME HERE}\AppData\Roaming\npm, append the following right after: ;C:\Program Files\nodejs
If the PATH variable contains information, but nothing regarding npm, append this to the end of the PATH: ;C:\Users\{YOUR USERNAME HERE}\AppData\Roaming\npm;C:\Program Files\nodejs
Now that the PATH variable is set correctly, you will still encounter errors. Manually go into the AppData directory and you will find that there is no npm directory inside Roaming. Manually create this directory.
Re-start the command prompt and npm will now work.
go to http://nodejs.org/
and hit the button that says "Download For ..."
This'll download the .msi (or .pkg for mac) which will do all the installation and paths for you, unlike the selected answer.
In addition to the answer from #StephanBijzitter I would use the following PATH variables instead:
%appdata%\npm
%ProgramFiles%\nodejs
So your new PATH would look like:
[existing stuff];%appdata%\npm;%ProgramFiles%\nodejs
This has the advantage of neiter being user dependent nor 32/64bit dependent.
New installers (.msi downloaded from https://nodejs.org) have "Add to PATH" option. By default it is selected. Make sure that you leave it checked.
Everything should be installed in %appdata% (C:\Users\\AppData\Roaming), not 'program files'.
Here's why...
The default MSI installer puts Node and the NPM that comes with it in 'program files' and adds this to the system path, but it sets the user path for NPM to %appdata% (c:\users[username]\appdata\roaming) since the user doesn't have sufficient priveleges to write to 'program files'.
This creates a mess as all modules go into %appdata%, and when you upgrade NPM itself - which NPM themselves recommend you do right away - you end up with two copies: the original still in 'program files' since NPM can't erase that, and the new one inn %appdata%.
Even worse, if you mistakenly perform NPM operations as admin (much easier on Windows then on *nix) then it will operate on the 'program files' copy of NPM node_modules. Potentially a real mess.
So, when you run the installer simply point it to %appdata% and avoid all this.
And note that this isn't anything wierd - it’s what would happen if you ran the installer with just user priveleges.
You should run the installer as administrator.
Run the command prompt as administrator
cd directory where msi file is present
launch msi file by typing the name in the command prompt
You should be happy to see all node commands work from new command prompt shell
I had the same problem, what helped we was turning of my anti virus protection for like 10 minutes while node installed and it worked like a charm.
The reason why you have to modify the AppData could be:
Node.js couldn't handle path longer then 256 characters, windows tend to have very long PATH.
If you are login from a corporate environment, your AppData might be on the server - that won't work. The npm directory must be in your local drive.
Even after doing that, the latest LTE (4.4.4) still have problem with Windows 10, it worked for a little while then whenever I try to:
$ npm install _some_package_ --global
Node throw the "FATAL ERROR CALL_AND_RETRY_LAST Allocation failed - process out of memory" error. Still try to find a solution to that problem.
The only thing I find works is to run Vagrant or Virtual box, then run the Linux command line (must matching the path) which is quite a messy solution.
For me I had to delete the nodejs folder in \program files and then when I went to install through the msi it worked. Seemed like when I uninstalled Node it didnt actually delete this file
I had the same problem, but after trying everything on this post unsuccessfully, I just had to restart.
So if you haven't tried restarting the computer after the installation, try it.
Restart your computer after installation

Resources