chdir

Change the current working directory.

Usage

var chdir = require( '@stdlib/process/chdir' );

chdir( path )

Changes the current working directory to the specified path.

var err = chdir( '/foo/bar' );

If the function encounters an error when attempting to change the working directory, the function returns an error; otherwise, the function returns null.

Examples

var cwd = require( '@stdlib/process/cwd' );
var chdir = require( '@stdlib/process/chdir' );

// Print the current working directory:
var dir = cwd();
console.log( dir );

// Change the current working directory to the directory of this file:
chdir( __dirname );

// Print the current working directory:
console.log( cwd() );

// Change the current working directory back to the original directory:
chdir( dir );

// Print the current working directory:
console.log( cwd() );