Skip to content

Instantly share code, notes, and snippets.

@thanhpv3380
thanhpv3380 / gist:02fe1f9bf449a36783614f3ee021c07a
Created October 3, 2025 17:15
freecodecamp-timestamp-microservice
// index.js
// where your node app starts
// init project
var express = require("express");
var app = express();
// enable CORS (https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
// so that your API is remotely testable by FCC
var cors = require("cors");
Swagger là một bộ công cụ mã nguồn mở để xây dựng OpenAPI specifications giúp bạn có thể thiết kế, xây dựng tài liệu và sử dụng REST APIs
* Cấu trúc:
1. Metadata:
- title: tên API của bạn
- description: thông tin chi tiết về API
- info: hỗ trợ về thông tin liên lạc, chứng chỉ, điều khoản sử dụng và những thông tin khác
2. Servers: Đây là phần sẽ chỉ dẫn của server để ta có thể test được API
3. Paths: định nghĩa những paths trong API như phương thức, tham số
- bắt đầu bằng từ khóa paths
- Sau đó là đến những path trong API (/user/{userId})
1. use database
2. db: show database hiện tại
3. show dbs: show list database hiện tại
-- condition: use database
4. db.dropDatabase(): delete database
5. db.createCollection(name, option(document))
- collection có thể ko cần khởi tạo, mà khởi tạo luôn document
+ example: db.[collectionName].insert({[data]});
6. db.[collectionName].drop: xóa collection
7. Insert