在 Node.js 命令提示符中更改目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31217771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:57:01  来源:igfitidea点击:

Change directory in Node.js command prompt

node.jscmddirectory

提问by Chirag Thakar

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:

我想移动到 Node.js 命令提示符中的另一个目录,但是当我打开 Node.js cmd 窗口时,它没有显示任何路径。这是 Node.js cmd 窗口的屏幕截图:

enter image description here

在此处输入图片说明

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

现在,如果我想将目录更改为,D:\abc我该怎么做呢?

回答by rink.attendant.6

That isn't the Node.js command prompt window. That is a language shell to run JavaScript commands, also known as a REPL.

那不是 Node.js 命令提示窗口。这是一个运行 JavaScript 命令的语言外壳,也称为REPL

In Windows, there should be a Node.js command promptin your Start menu or start screen:

在 Windows 中,您的开始菜单或开始屏幕中应该有一个Node.js 命令提示符

Windows Search for node.js

Windows 搜索 node.js

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

这将打开一个命令提示符窗口,如下所示:

Node.js command prompt window

Node.js 命令提示窗口

From there you can switch directories using the cdcommand.

从那里您可以使用cd命令切换目录。

回答by Venkat Kondapaneni

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

切换到另一个目录 process.chdir("../");

回答by Roman

If you mean to change default directory for "Node.js command prompt", when you launch it, then (Windows case)

如果您要更改“Node.js 命令提示符”的默认目录,则在启动它时,则(Windows 案例)

  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%"
    
  1. 转到安装 NodeJS 的目录
  2. 找到文件 nodevars.bat
  3. 以管理员身份用编辑器打开
  4. 更改行中的默认路径,如下所示

    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:

如果您打算在启动“Node.js 命令提示符”时更改一次目录,请在 Node.js 命令提示符下执行以下命令:

     cd c:/MyDirectory/

回答by Bar Cohen

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

将 \d [dir] 属性添加到 cd 命令,如下所示:

cd \d %yourdir%:\

回答by Kalon Acharjee

.helpwill show you all the options. Do .exitin this case

.help将显示所有选项。在这种情况下执行.exit

回答by JatinP

Type .exitin command prompt window, It terminates the node repl.

在命令提示符窗口中键入.exit,它终止节点 repl。