2

What does ./ mean? I assume that it is used to search a path, but I am not sure if that is true. I know that, for example, in C# if I want to search a path I can use ../../file.exe.

Currently what I want is to run a command in node.js from my application in NW.js with the following code:

var exec = require('child_process').exec;

exec('node ./server.js', function(error, stdout, stderr) {
    console.log('stdout: ', stdout);
    console.log('stderr: ', stderr);

    if (error !== null) {
        console.log('exec error: ', error);
    }
});

However, the code above does not produce the desired results. I believe it is because I don't know how to search the path of server.js that I want to run.

Jonny Henly
  • 4,023
  • 4
  • 26
  • 43
Dlanor
  • 266
  • 2
  • 13

2 Answers2

6

I'm assuming you're using some form of *NIX.

./ is your current directory. So, for example, using cd ./examplefolder is perfectly valid.

../ is the parent directory. So, for example, you can use cd ../ to go up a level in the directory hierarchy.

~ is your home directory. So, if you're at ~/example/example2/example3, you can use cd ~/ to return to home quickly.

If you're using nodejs, simply using the command node yourfilehere.js will execute it, if your current directory is the one you're launching the file from. Using node ../yourfilehere.js works just as well... but then again, so does cd ../ and node yourfilehere.js.

Jonny Henly
  • 4,023
  • 4
  • 26
  • 43
2

In terms of node.js, I'll go into a little bit more detail than the commenter.

./ means that you should execute a file in the current directory. To see the current directory and if you're on unix, type pwd. ../ will mean execute a file in the "previous" directory. In graph theory this would mean the parent node.

If you don't specify a path to the executable, then the system will look in the PATH

Ryan
  • 14,392
  • 8
  • 62
  • 102
  • I know this is true for Linux commands and scripts executed directly. But is it really also true for the argument passed to node? – Alex May 26 '16 at 20:00