Node.js | os.tmpdir() Method
Last Updated :
14 Feb, 2020
The os.tmpdir() method is an inbuilt application programming interface of the os module which is used to get path of default directory for temporary files of the operating system.
Syntax:
os.tmpdir()
Parameters: This method does not accept any parameters.
Return Value: This method returns a string specifies the path to the default directory for temporary files of the operating system.
Below examples illustrate the use of os.tmpdir() method in Node.js:
Example 1:
const os = require( 'os' );
console.log(os.tmpdir());
|
Output:
C:\Users\gekcho\AppData\Local\Temp
Example 2:
const os = require( 'os' );
console.log( "home directory:" + getUserHome());
console.log( "temp directory:" + os.tmpdir());
function getUserHome() {
return process.env[(process.platform == 'win32' )
? 'USERPROFILE' : 'HOME' ];
}
|
Output:
home directory:C:\Users\gekcho
temp directory:C:\Users\gekcho\AppData\Local\Temp
Note: The above program will compile and run by using the node index.js
command.
Reference: https://nodejs.org/api/os.html#os_os_tmpdir
Share your thoughts in the comments
Please Login to comment...