Change directory in Node.js command prompt

152,477

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:

Windows Search for node.js

Which will open a command prompt window that looks like this:

Node.js command prompt window

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)

  1. go the directory where NodeJS was installed
  2. find file nodevars.bat
  3. open it with editor as administrator
  4. 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%:\
Share:
152,477
Chiragkumar Thakar
Author by

Chiragkumar Thakar

Updated on July 09, 2022

Comments

  • Chiragkumar Thakar
    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:

    enter image description here

    Now if i want to change directory to D:\abc then how can i do it here?

  • kirtan403
    kirtan403 over 8 years
    I am not able to change the directory using the shown command prompt.
  • Megha
    Megha almost 8 years
    Even I am not able to change directory. Any inputs?
  • rink.attendant.6
    rink.attendant.6 almost 8 years
    @Meghaa I've added a new screenshot showing how to change drives and directories
  • Megha
    Megha almost 8 years
    @rink.attendant.6: Thanks a lot
  • nam
    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 to C:\Program Files\nodejs that is the install directory of nodejs on my Windows 10. I than ran cd c:\Test and it changed the command line path to c:\Test>.
  • yohosuff
    yohosuff over 4 years
    You can also drop the trailing slash (ie. process.chdir("..")).