# [GDSC] NodeJS [TOC] > 我不是 Javascript 專業,講錯歡迎指教 --- ## 個人對 NodeJS 的看法與聽聞 - 如果你只會 JavaScript - 如果你想嘗試後端 - 如果你做小型專案 - ~~如果你想看到 Callback Hell~~ >[!Note] More details > GeeksforGeeks - [Pros & Cons of NodeJS](https://www.geeksforgeeks.org/the-pros-and-cons-of-node-js-in-web-development/) --- ## Introduction ### Intro to NodeJS - **Runtime Environment** 基於 Chrome V8 JavaScript 引擎構建,提供 JavaScript 的執行環境 - **Non-blocking I/O** 可以進行大量併發 - **Event-driven** 透過事件 (event) 以及回調 (callback) 處理異步操作 (asynchronous) - **Single-thread** - 主要使用 **npm** 套件管理 - **使用 JavaScript** :::info 關於 Chrome V8 - 高性能編譯技術與優化, e.g., Just-In-Time (JIT), Inline Caching, (IC) - 垃圾回收 (garbage collection) - 跨平台 - 可被嵌入 NodeJS 即利用其可被嵌入的特性,讓開發者可以在伺服器端使用 JavaScript ::: ### Intro to Express - NodeJS 的框架 (framework) - Middleware 通常會是一些安全驗證、請求解析、響應檔頭、錯誤處理、日誌紀錄之類的 - 使用模板引擎 (template engine) e.g., [Pug](https://pugjs.org/api/getting-started.html) ### Intro to MongoDB 因為我們不是講 DB 的課,所以便不深入介紹 - NoSQL 使用文檔儲存,若是用 Mapping 為 ODM (Object Document Mapping) - Easy to use UI - [Atlas](https://cloud.mongodb.com/) - 專門 for node.js 的 ODM - [mongoose](https://mongoosejs.com/) --- ## CommonJS v.s. ECMAScript ### CommonJS - 同步編譯 = 執行時加載 #### Example ```javascript= const module = require('module'); module.exports = { // Implementation }; ``` ### ECMAScript - 靜態編譯 = 編譯時加載 :+1: 編譯優化 (tree shaking): 簡單來說就是將未使用到的程式碼砍掉,減少輸出包的大小 (打包工具例如: Webpack, Rollup, Parcel) :+1: 更好地處理循環依賴 (circular dependency) :+1: 編譯時就檢查到錯誤 #### Example ```javascript= import { ... } from 'module'; export const exModule = { // Implementation }; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up