File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ Provides a few basic operating-system related utility functions.
66
77Use ` require('os') ` to access this module.
88
9+ ## os.tmpDir()
10+
11+ Returns the operating system's default directory for temp files.
12+
913## os.hostname()
1014
1115Returns the hostname of the operating system.
Original file line number Diff line number Diff line change @@ -30,13 +30,22 @@ exports.cpus = binding.getCPUs;
3030exports . type = binding . getOSType ;
3131exports . release = binding . getOSRelease ;
3232exports . networkInterfaces = binding . getInterfaceAddresses ;
33+
3334exports . arch = function ( ) {
3435 return process . arch ;
3536} ;
37+
3638exports . platform = function ( ) {
3739 return process . platform ;
3840} ;
3941
42+ exports . tmpDir = function ( ) {
43+ return process . env . TMPDIR ||
44+ process . env . TMP ||
45+ process . env . TEMP ||
46+ ( process . platform === 'win32' ? 'c:\\windows\\temp' : '/tmp' ) ;
47+ } ;
48+
4049exports . getNetworkInterfaces = function ( ) {
4150 return exports . networkInterfaces ( ) ;
4251} ;
Original file line number Diff line number Diff line change @@ -27,6 +27,18 @@ var assert = require('assert');
2727var os = require ( 'os' ) ;
2828
2929
30+ process . env . TMPDIR = '/tmpdir' ;
31+ process . env . TMP = '/tmp' ;
32+ process . env . TEMP = '/temp' ;
33+ var t = ( process . platform === 'win32' ? 'c:\\windows\\temp' : '/tmp' ) ;
34+ assert . equal ( os . tmpDir ( ) , '/tmpdir' ) ;
35+ process . env . TMPDIR = '' ;
36+ assert . equal ( os . tmpDir ( ) , '/tmp' ) ;
37+ process . env . TMP = '' ;
38+ assert . equal ( os . tmpDir ( ) , '/temp' ) ;
39+ process . env . TEMP = '' ;
40+ assert . equal ( os . tmpDir ( ) , t ) ;
41+
3042var hostname = os . hostname ( ) ;
3143console . log ( 'hostname = %s' , hostname ) ;
3244assert . ok ( hostname . length > 0 ) ;
You can’t perform that action at this time.
0 commit comments