Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change directory in Node.js command prompt

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?

like image 576
Chiragkumar Thakar Avatar asked Jul 04 '15 06:07

Chiragkumar Thakar


People also ask

How do I change Active directory in CMD?

To change current working directory under the current drive, use command " cd new-path " (change directory).

How do I change the terminal in node JS?

If you need to change the default terminal, select the dropdown menu and choose Select Default Shell. In the terminal, enter: node app. js . You should see the output: "Hello World".


3 Answers

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.

like image 66
rink.attendant.6 Avatar answered Oct 21 '22 09:10

rink.attendant.6


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

like image 23
Venkat Kondapaneni Avatar answered Oct 21 '22 10:10

Venkat Kondapaneni


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/
like image 8
Roman Avatar answered Oct 21 '22 09:10

Roman