0% found this document useful (0 votes)
60 views1 page

Node.js Module & File Handling Guide

Node.js modules allow code reuse through requires and exports. The HTTP module adds headers using res.writeHead() with status codes like 200. The File System module reads, writes, appends, and deletes files using functions like readFile(), writeFile(), and unlink(). Popular Node.js packages include MySQL for databases and buffers for binary data storage and manipulation.

Uploaded by

Vũ Đức Văn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views1 page

Node.js Module & File Handling Guide

Node.js modules allow code reuse through requires and exports. The HTTP module adds headers using res.writeHead() with status codes like 200. The File System module reads, writes, appends, and deletes files using functions like readFile(), writeFile(), and unlink(). Popular Node.js packages include MySQL for databases and buffers for binary data storage and manipulation.

Uploaded by

Vũ Đức Văn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

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

You might also like