How to work with directories in Gulp? - node.js

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.

Related

How to reset the $PATH?

I confess, I very don't know what I'm talking about.
This morning I wanted to install Javascripting (to learn javascript) on my Mac, so I watch a video to do it:
I downloaded node.js and I installed it;
after that I opened the terminal and I type: npm install -g javascripting and here I've got some errors. I tried to search the solution but I think I created a big problem:
Basically I modified the $PATH several times and now the situation is this.
If I run echo PATH it displays
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I wanted to clean it all so I tried to type:
brew uninstall --force node
but the terminal says:
zsh: command not found: brew
I can't do anything.
Please, someone help me :(
If you just want to clear this environment variable, just do 'unset PATH'.
But, be aware that PATH is used by a shell (i.e. bash, ksh, zsh...) to look for programs in these directories. clearing it has side effects.
The 'brew' program is somewhere, to find it, you could use the following command :
find / -name 'brew' -print
It can take a little while to find it.
Either use that found path, or add the directory where that program is found to the PATH variable, as in
PATH=$PATH:/location_of_brew_program; export PATH

How do I run a task inside nodejs, I get npm run error

Alright, I have a extremelly newbie question to ask. How do I run the code I have on my visual estudio code?
I see my files with the code inside (the code I took it from a github public tutorial) now, in one part of the tutorial it says "let's check how it works" and types the command npm run install and then inside of the IDE terminal the code starts to run.
Now, unfortunately, the tutorial never mentions in what file we are (is it a new file) or if it's just the IDE main terminal calling up the program main function.
So, what I tried to do was to put the same line of code on the terminal of visual estudio code, and I get this error:
'npm' is not recognized as internal or external command, operable program or batch file.
Now, what I am thinking is that I need to type npm install in a specific window, but on the tutorial is just stated "let's take a look at the program"
sorry, I feel as I am asking were do I put the keys to enter my house, it is an extremelly simple/dumb question, but I guess these little details are what make newbies like me get lost in the most simple tasks.
I also tried the menu on visual studio code, click on terminal and then on run task and then select one of the options that are on the default -install or npm run start. Same error.
You need to install npm globally. If you are using Windows you will probably need to add it in environment variables also. Check also if you have install Node.js (when you install Node.js, npm will be automatically installed).
You can check this Docs: https://docs.npmjs.com/downloading-and-installing-node-js-and-npm
Once you do that you can use npm as a command in your terminal.

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.

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

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