@stdlib/process-chdir

Change the current working directory.

Usage no npm install needed!

<script type="module">
  import stdlibProcessChdir from 'https://cdn.skypack.dev/@stdlib/process-chdir';
</script>

README

chdir

NPM version Build Status Coverage Status dependencies

Change the current working directory.

Installation

npm install @stdlib/process-chdir

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() );

Notice

This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2021. The Stdlib Authors.