NODE.JS的基本系统模块操作样例

就练练手,

嘿嘿,说不定,写服务器脚本也可以哟。

console.log('Currently executing file is ' + __filename);
console.log('It is located in ' + __dirname);
console.log('Starting in ' + process.cwd());

try {
    process.chdir('/');
} catch (error) {
    console.error('chdir: ' + error.message);
}
console.log('Current working directory is now ' + process.cwd());

var fs = require('fs');

fs.readFile(__filename, function(error, data) {
    if (error) {
        return console.error(error.message);
    }
    console.log(data);
});

fs.readFile(__filename, {
    encoding: 'utf8'
    },function(error, data) {
    if (error) {
        return console.error(error.message);
    }
    console.log(data);
});

var data;
try {
    data = fs.readFileSync(__filename);
    console.log(data);
} catch(error) {
    console.error(error.message);
}

NODE.JS的基本系统模块操作样例

上一篇:JAVA基础代码分享--求圆面积


下一篇:LINQ to SQL大全