1.
Mo dau voi Nodejs
Module giong nhu thu vien, su dung ham require() de goi module
Co the tao ra module, su dung keyword "exports", luu thanh [Link]
Goi module cua minh bang cach require('./mymodule')
2. [Link] HTTP module
Them wirteHead() de dinh dang ban tin hien len
[Link](200, {'Content-Type': 'text/html'});
tham so dau tien la status code, 200 nghia la OK
Tham so req cua createServer() la yeu cau cua client
write([Link]) => request of client
ex: localhost:8080/summer
/summer
3. File Server
su dung module ‘fs’
cac ham hay su dung :
- readFile()
- appendFile() : viet them noi dung vao file, neu file chua co thi tao file
- open() : co them cai “flag” neu la ‘w’ thi write, khong co “flag” thi tao file trong
- writeFile() : replace noi dung bang noi dung khac
- unlink() : xoa file
_ rename() : rename
4. Download package
5. Database in NodeJs
su dung package: var mysql = require(‘mysql’);
tao connect : var con = [Link]()
su dung connect de tao query :
[Link](function(err))
6. Buffer
giong mang array,
- write()
- toString()
- toJSON()
- concat()
- compare()
-copy()
- slice() : cat buffer