Change directory in Node.js command prompt
Solution 1
That isn't the Node.js command prompt window. That is a language shell to run JavaScript commands, also known as a REPL.
In Windows, there should be a Node.js command prompt in your Start menu or start screen:
Which will open a command prompt window that looks like this:
From there you can switch directories using the cd
command.
Solution 2
To switch to the another directory process.chdir("../");
Solution 3
If you mean to change default directory for "Node.js command prompt", when you launch it, then (Windows case)
- go the directory where NodeJS was installed
- find file nodevars.bat
- open it with editor as administrator
-
change the default path in the row which looks like
if "%CD%\"=="%~dp0" cd /d "%HOMEDRIVE%%HOMEPATH%"
with your path. It could be for example
if "%CD%\"=="%~dp0" cd /d "c://MyDirectory/"
if you mean to change directory once when you launched "Node.js command prompt", then execute the following command in the Node.js command prompt:
cd c:/MyDirectory/
Solution 4
Add the \d [dir] attribute to the cd command like this:
cd \d %yourdir%:\
![Chiragkumar Thakar](https://i.stack.imgur.com/N3HsQ.png?s=256&g=1)
Chiragkumar Thakar
Updated on July 09, 2022Comments
-
Chiragkumar Thakar almost 2 years
I want to move to another directory in Node.js command prompt but when I open the Node.js cmd window it doesn't show me any path. Here is the screenshot of the Node.js cmd window:
Now if i want to change directory to
D:\abc
then how can i do it here? -
kirtan403 over 8 yearsI am not able to change the directory using the shown command prompt.
-
Megha almost 8 yearsEven I am not able to change directory. Any inputs?
-
rink.attendant.6 almost 8 years@Meghaa I've added a new screenshot showing how to change drives and directories
-
Megha almost 8 years@rink.attendant.6: Thanks a lot
-
nam over 5 years@Megha For example, in my case I wanted to change directory to
C:\Test
. When I ran>C:
it changed the directory toC:\Program Files\nodejs
that is the install directory of nodejs on my Windows 10. I than rancd c:\Test
and it changed the command line path toc:\Test>
. -
yohosuff over 4 yearsYou can also drop the trailing slash (ie.
process.chdir("..")
).