读<了不起的Node.js>-07.对命令行一探究竟

2018-08-04  本文已影响0人  在路上的海贼

CLI(Command Line Interface for batch scripting)

argv

工作目录

环境变量

退出

信号

process.on('SIGKILL',function(){
    //信号已经收到
});

ANSI转义码

对fs一探究竟

stream(流)

fs.readFile('test.txt', function (err, contents) {
    // console.log(contents.toString());
});

let stream = fs.createReadStream('test.txt');
stream.on('data', function (chunk) {
    console.log(chunk);
});
stream.on('end', function (chunk) {
    console.log(chunk);
});

监视


 let fs = require('fs');
<!--let stream = fs.createReadStream('test.txt');-->

//获取目录下的所有文件
let files = fs.readdirSync(process.cwd());
console.log(process.cwd());

files.forEach(function (file) {
    //监听后缀为.css的文件
    console.log(file);
    if (/\.css/.test(file)) {
        fs.watchFile(process.cwd() + '/' + file, function () {
            console.log(' - ' + file + ' changed!');
        })
    }
});
上一篇 下一篇

猜你喜欢

热点阅读