Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change default directory in node.js? (Windows)

When I try to tun my project on node, I have to write the full path for my javascript file because the default value node uses is C:\Users\MyUser and I refuse to use it.

I've been trying to find how to change this but have not found it anywhere. I even tried searching the directory manually for it and had no luck finding it.

Could anyone point me on how to fix this annoying little problem I have?

like image 697
Mr. Adobo Avatar asked Apr 21 '13 07:04

Mr. Adobo


2 Answers

You can mean to change default directory for "Node.js command prompt", when you launch it. If so, 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 you can run in the command line of NodeJS command prompt:

     cd c:/MyDirectory/
like image 72
Roman Avatar answered Sep 20 '22 05:09

Roman


Node's "default" directory is the Windows home directory. Note, you can change node's home directory using process.chdir(directory)

like image 23
Brian Attwell Avatar answered Sep 23 '22 05:09

Brian Attwell