VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-process-chdir-method/

⇱ Node.js process.chdir() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js process.chdir() Method

Last Updated : 28 Apr, 2025

The process.chdir() method is an inbuilt application programming interface of the process module which is used to change the current working directory. Syntax:

process.chdir( directory )

Parameters: This method accepts single parameter as mentioned above and described below:

  • directory: It is required parameter that specifies the path to the directory to which current working directory to be changed.

Return Value: This method does not return any value on success but throws an exception if fails to change directory specifying that "no such file or directory". Below examples illustrate the use of process.chdir() method in Node.js: Example 1: 

Output:

directory has successfully been changed

Example 2: 

Output:

current working directory: C:\nodejs\g\process
working directory after changing: C:\nodejs\g\os

Note: The above program will compile and run by using the node filename.js command. Reference: https://nodejs.org/api/process.html#process_process_chdir_directory

Comment

Explore