Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

Notes

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:
var err = chdir( __dirname );
if ( err ) {
    console.error( err.message );
}

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

// Change the current working directory back to the original directory:
err = chdir( dir );
if ( err ) {
    console.error( err.message );
}

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