Skip to main content

Nodejs Awesome

tip
  • 最好选择 TypeScript 开发的或支持 TypeScript 的
  • TypeScript 的 decorator 比 Java 的 Annotation 弱得多
    • 不支持获取字段实际类型信息 - 因为不存在这样的信息
Nodejs 后端开发不太活跃

最近一两年 (2020-2021),可能是因为 Go 和 Rust 的盛行,导致 Nodejs 的后端开发弱化了,很多项目开发都不太活跃。

DB

driver pkgdbnotes
pg pg-hstorePostgreSQL
mysql2MySQL
mariadbMariaDB
sqlite3SQLite
better-sqlite3SQLite同步接口
tediousMicrosoft SQL Server
ibm_dbDB2
// PostgreSQL
// 支持的环境变量 https://www.postgresql.org/docs/current/libpq-envars.html
// PGHOST PGPORT PGUSER PGPASSWORD PGDATABASE PGSSLMODE PGOPTIONS
// 修改 search_path PGOPTIONS=-csearch_path=public
const { Client } = require('pg');
const client = new Client();
await client.connect();
const res = await client.query('SELECT $1::text as message', ['Hello world!']);
console.log(res.rows[0].message); // Hello world!
await client.end();

Env

# n on alpine
apk add bash curl ca-certificates libstdc++ libgcc
curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n
chmod u+x n
install -t /usr/local/bin n

# 官方镜像
# N_NODE_MIRROR=https://unofficial-builds.nodejs.org/download/release ./n --arch x64-musl lts
# 国内镜像
N_NODE_MIRROR=https://npmmirror.com/mirrors/node-unofficial-builds ./n --arch x64-musl lts

# 非 ROOT
export PATH=$HOME/n/bin:$PATH
export N_PREFIX=$HOME/n

Library

Web

  • [hono]
  • fastify
    • 🌟 推荐
  • express
  • koa
    • 🚧 开发停滞

Framework

Network

  • node-fetch - NodeJS v18 后内置 fetch
  • https-proxy-agent
  • socks-proxy-agent
  • proxy-from-env
  • websocket
  • ws
  • [µWebSockets.js]

Server

FFI

Sandbox/VM