nodeJS exec does not work for “cd ” shell cmd

Each command is executed in a separate shell, so the first cd only affects that shell process which then terminates. If you want to run git in a particular directory, just have Node set the path for you:

exec('git status', {cwd: '/home/ubuntu/distro'}, /* ... */);

cwd (current working directory) is one of many options available for exec.

Leave a Comment