-
回顾
- widows和linux通信安装SecureFXPortable
- linux和linux通信拷贝文件
scp命令
nodejs 模块系统的操作
npm 管理第三方组件,模块
-
模块的使用:
- mkdir 1021
- cd 1021
- vim one.js
- vim app.js
one.js:
exports.zhouwu = function() {
console.log("111");
}
app.js
// 引用模块
var abc = require('./one');
console.log(abc);//zhouwu:[Function]
abc.zhouwu();//111
one.js:
function liwei() {
var t;
this.jiangke = function(t){
console.log(t);
}
}
model.exports = liwei;
abc.js:
var abc = require('./one');
cc = new abc();
console.log(cc);//liwei{jiangke:[Function]}
cc,jiangke(zhouwu);
-
vim 1.txt
wo de wei xin
- touch f.js
-
vim f.js
var fs = require('fs')
fs.readFile('./1.txt',(err,data) => {
if(err) {
throw err;
}
console.log(data.toString());
})
-
http:
touch server.js
var http = require('http');
var ip = "192.168.84.128";
var port = 3000;
http.createServer((req,res) => {
res.writeHead('200',{'content-type':'text/html'});
res.write('<html>');
res.write('<meta charset="utf-8">');
res.write('<body>');
res.write('<hl>卧槽,今天星期五,明天不上班!');
res.write('</body>');
res.write('</html>');
res.end();
}).listen(port, ip, () =>{
console.log('server is run!');
});
var http = require('http');
var ip = "192.168.84.128";
var port = 3000;
http.createServer((req,res) => {
console.log(req);
}).listen(port, ip, () =>{
console.log('server is run!');
});