This commit is contained in:
isaacs 2012-06-12 19:05:51 -07:00
Родитель 0dba4ad0f9
Коммит a11bf99ce0
3 изменённых файлов: 25 добавлений и 0 удалений

Просмотреть файл

@ -6,6 +6,10 @@ Provides a few basic operating-system related utility functions.
Use `require('os')` to access this module. Use `require('os')` to access this module.
## os.tmpDir()
Returns the operating system's default directory for temp files.
## os.hostname() ## os.hostname()
Returns the hostname of the operating system. Returns the hostname of the operating system.

Просмотреть файл

@ -30,13 +30,22 @@ exports.cpus = binding.getCPUs;
exports.type = binding.getOSType; exports.type = binding.getOSType;
exports.release = binding.getOSRelease; exports.release = binding.getOSRelease;
exports.networkInterfaces = binding.getInterfaceAddresses; exports.networkInterfaces = binding.getInterfaceAddresses;
exports.arch = function() { exports.arch = function() {
return process.arch; return process.arch;
}; };
exports.platform = function() { exports.platform = function() {
return process.platform; return process.platform;
}; };
exports.tmpDir = function() {
return process.env.TMPDIR ||
process.env.TMP ||
process.env.TEMP ||
(process.platform === 'win32' ? 'c:\\windows\\temp' : '/tmp');
};
exports.getNetworkInterfaces = function() { exports.getNetworkInterfaces = function() {
return exports.networkInterfaces(); return exports.networkInterfaces();
}; };

Просмотреть файл

@ -27,6 +27,18 @@ var assert = require('assert');
var os = require('os'); var os = require('os');
process.env.TMPDIR = '/tmpdir';
process.env.TMP = '/tmp';
process.env.TEMP = '/temp';
var t = ( process.platform === 'win32' ? 'c:\\windows\\temp' : '/tmp' );
assert.equal(os.tmpDir(), '/tmpdir');
process.env.TMPDIR = '';
assert.equal(os.tmpDir(), '/tmp');
process.env.TMP = '';
assert.equal(os.tmpDir(), '/temp');
process.env.TEMP = '';
assert.equal(os.tmpDir(), t);
var hostname = os.hostname(); var hostname = os.hostname();
console.log('hostname = %s', hostname); console.log('hostname = %s', hostname);
assert.ok(hostname.length > 0); assert.ok(hostname.length > 0);