48

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?

8 Answers 8

84

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I am not able to change the directory using the shown command prompt.
Even I am not able to change directory. Any inputs?
@Meghaa I've added a new screenshot showing how to change drives and directories
@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>.
27

To switch to the another directory process.chdir("../");

1 Comment

You can also drop the trailing slash (ie. process.chdir("..")).
8

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/

Comments

1

Add the \d [dir] attribute to the cd command like this:

cd \d %yourdir%:\

Comments

1
  1. Open file nodevars.bat
  2. Just add your path to the end, "%HOMEDRIVE%%HOMEPATH% /file1/file2/file3
  3. Save file nodevars.bat

This work even with Swedish words

Comments

-1

OR IF YOU GUYS ARE ON WINDOWS . YOU CAN USE POWER SHELL .... IT WORKS THE SAME WAY

YOU CAN USE cd d:/ TO CHANGE DIRECTORY ...

Comments

-2

Type .exit in command prompt window, It terminates the node repl.

Comments

-2

.help will show you all the options. Do .exit in this case

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.