5

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?

Stuart M
  • 11,458
  • 6
  • 45
  • 59
Mr. Adobo
  • 815
  • 1
  • 12
  • 24
  • 1
    Node.js doesn't itself have a "*default directory*." The starting [working directory](http://nodejs.org/api/process.html#process_process_cwd) ("[Home directory](http://en.wikipedia.org/wiki/Home_directory)") is determined by Windows. – Jonathan Lonowski Apr 21 '13 at 07:42
  • Wow, silly me! No wonder I could never find anything about this! You should post this as your answer. – Mr. Adobo Apr 21 '13 at 07:59
  • Need some more info. Are you doing something like **> c:\Users\MyUser\node your_project** or **>node c:\users\MyUser\your_project** ? – naquiuddin Apr 21 '13 at 11:11
  • Andyfan, I was doing the second one. What Jonathan said was my problem though (and I feel like such a noob for not noticing it). – Mr. Adobo Apr 22 '13 at 14:08

3 Answers3

7

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/
Roman
  • 19,236
  • 15
  • 93
  • 97
1

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

Brian Attwell
  • 9,239
  • 2
  • 31
  • 26
-1

There is a nodevars.bat file that launches the command shell in the programs folder.

  • 3
    Welcome to StackOverflow! Perhaps you can add more details, to explain better the most important parts of your answer. Have a read of [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) for more information. Also, once you get more reputation, you will be able to post this as a comment rather than an answer, which would be more appropriate. – Francesco B. Apr 02 '18 at 16:41