工具模块:
os模块:
1.os.tmpdir();
2.os.hostname();
3.os.type();
4.os.platform();
5.os.loadavg();
6.os.totalmem();
7.os.freemem();
8.os.cpus();
9.os.networkinterfaces();
**
// web模块
os=require('os');
// tot=os.totalmem();
// tot=os.freemem();
// tot=os.tmpdir();
// tot=os.hostname();
// tot=os.type();
// tot=os.platform();
// tot=os.loadavg();
// tot=os.cpus();
tot=os.networkInterfaces();
console.log(tot);
path模块:
1.path.dirname();
2.path.basename();
3.path.extname();
4.path.parse();
5.path.format();
path.format把路径对象转成路径字符串
// web模块
path=require('path');
pobj={
root: '/',
dir: '/usr/local/www',
base: 'index.sh',
ext: '.sh',
name: 'index'
};
str=path.format(pobj);
str2=str.replace('\\','/');
console.log(str2);
path模块使用
path=require('path');
str='/usr/local/www/index.sh';
// dname=path.dirname(str);
// dname=path.basename(str);
// dname=path.extname(str);
dname=path.parse(str);
console.log(dname);
dns模块:
1.dns.lookup();
dns.lookup方法
var dns = require('dns');
dns.lookup('www.github.com', function onLookup(err, address, family) {
console.log('ip 地址:', address);
dns.reverse(address, function(err, hostnames) {
if (err) {
console.log(err.stack);
}
console.log('反向解析 ' + address + ': ' + JSON.stringify(hostnames));
});
});
es6中函数改进的地方
(()=>{
console.log('hello world!');
})();
net模块
const net=require('net');
chat=net.createServer();
chat.on('connection',function(client){
client.write('hello world');
client.end();
});
chat.listen(9000);
console.log('telnet server ok!');
net通讯聊天
const net=require('net');
chat=net.createServer();
chat.on('connection',function(client){
client.write('hello world');
client.on('data',function(data){
console.log('Adai: '+data.toString());
});
});
chat.listen(9000);
console.log('telnet server ok!');
**
**
**
**
**
**
**
**
**
**
**