chdir

process.chdir(directory)

Changes the current working directory of the process or throws an exception if that fails.

console.log('Starting directory: ' + process.cwd());
try {
  process.chdir('/Users');
  console.log('New directory: ' + process.cwd());
}
catch (err) {
  console.error('chdir: ' + err);
}

Result with existing directory:

$ node doc_test.js 
Starting directory: /Users/johndoe
New directory: /Users

Result with non-existing directory:

$ node doc_test.js 
Starting directory: /Users/johndoe
chdir: Error: No such file or directory

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s