1,全局变量
- __dirname 当前模块的目录名
- __filename 当前模块的文件名
- require() 用于引入模块、 JSON、或本地文件
2,fs模块
// 同步读取目录下的内容,返回目录中的文件名和文件夹名数组(不递归)
fs.readdirSync(path)
// 异步读取,使用回调操作
fs.readdir(path, function(err, names) {
// names -> ["index.html", "src"]
})
// 异步stat方法
fs.stat(path, function(err, stat) {
// stat.isFile() 是否为文件
// stat.isDirectory() 是否为文件夹
})
3,http模块
// 返回新建的 http.Server 实例后监听连接
http.createServer(function (req, res) {
res.end('Hello')
}).listen(3000, function () {
console.log('3000')
})