nodejsグローバルオブジェクト
1568 ワード
// global objects in nodejs:
// current JavaScript file:
console.log('current js file: ' + __filename);
// current JavaScript file dir:
console.log('current js dir: ' + __dirname);
process.name = 'Sample Nodejs';
// process.argv :
console.log('arguments: ' + JSON.stringify(process.argv));
// process.cwd() :
console.log('cwd: ' + process.cwd());
// , Windows 'C:\\Windows\\System32'
process.chdir('/private/tmp');
console.log('cwd: ' + process.cwd());
// process.nextTick() :
process.nextTick(function () {
console.log('nextTick callback!');
});
console.log('nextTick was set!');
// :
process.on('exit', function (code) {
console.log('about to exit with code: ' + code);
});
1.com nsole> global.console
Console {
log: [Function: bound ],
info: [Function: bound ],
warn: [Function: bound ],
error: [Function: bound ],
dir: [Function: bound ],
time: [Function: bound ],
timeEnd: [Function: bound ],
trace: [Function: bound trace],
assert: [Function: bound ],
Console: [Function: Console] }
2.process> process === global.process;
true
> process.version;
'v5.2.0'
> process.platform;
'darwin'
> process.arch;
'x64'
> process.cwd(); //
'/Users/michael'
> process.chdir('/private/tmp'); //
undefined
> process.cwd();
'/private/tmp'
3.