随笔分类 -  Node.js

1 2 3 4 5 ··· 10 下一页
摘要:远程通信方式 通信方式: Stdio: 推荐,高效、简洁、本地 Streamable HTTP: 远程 前置知识 SSE 全称 Server-Sent Events,中文是“服务器发送事件”。是一种基于 HTTP 的单向通信协议,由浏览器发起连接,服务器可以持续不断地向客户端推送数据。 你可以把它想 阅读全文
posted @ 2025-10-06 02:53 Zhentiw 阅读(19) 评论(0) 推荐(0)
摘要:chokidar chokidar 是一个功能强大、跨平台、性能优秀的 文件系统监听库,适用于 Node.js 环境,底层使用原生 fs.watch 和 fs.watchFile,并在 macOS/Linux 上优先使用更高效的 fsevents(若可用)。 基本用法: import chokida 阅读全文
posted @ 2025-10-03 13:54 Zhentiw 阅读(14) 评论(0) 推荐(0)
摘要:SSE SSE(Server-Sent Events) 是一种浏览器原生支持的、单向的流式通信协议: 服务器 → 客户端 持续不断推送数据(比如:消息、token、进度) 它基于 HTTP 协议,使用 MIME 类型 text/event-stream。 核心特性 单向通信:只能从服务端推送到客户端 阅读全文
posted @ 2025-09-06 19:52 Zhentiw 阅读(30) 评论(0) 推荐(0)
摘要:When you run node.js you can run node --expose-gc index.js Which will allow you manully cleanup gc: global.gc() Map For map, it is easy to cost memory 阅读全文
posted @ 2024-11-26 20:41 Zhentiw 阅读(27) 评论(0) 推荐(0)
摘要:Using the Node.js glob function as a practical example, you'll learn how Array.fromAsync facilitates the creation of arrays from asynchronous iterable 阅读全文
posted @ 2024-10-28 15:43 Zhentiw 阅读(12) 评论(0) 推荐(0)
摘要:You can create a javascript file as a bash file: #!/usr/bin/env node console.log("Hello World!") Run the script: ./script.js 阅读全文
posted @ 2024-08-11 22:04 Zhentiw 阅读(12) 评论(0) 推荐(0)
摘要:Normally you need to put require("dotenv").config() console.log(process.env.TEST) to access env vars WIth --node-fileflag you don't need to do that an 阅读全文
posted @ 2024-01-22 14:25 Zhentiw 阅读(51) 评论(0) 推荐(0)
摘要:# Create a node cli ## Init a project Run: `npm run init` Let's say we want to create a cli command call `note-dev`, let's add this into `package.json 阅读全文
posted @ 2023-08-26 16:15 Zhentiw 阅读(20) 评论(0) 推荐(0)
摘要:logger.ts // .env LOGGER_LEVEL=debug // logger.ts import * as winston from "winston"; export const logger = winston.createLogger({ level: process.env. 阅读全文
posted @ 2023-04-26 15:47 Zhentiw 阅读(20) 评论(0) 推荐(0)
摘要:import * as dotenv from "dotenv"; const result = dotenv.config(); if (result.error) { console.log('Error loading environment variables, aborting.') pr 阅读全文
posted @ 2023-04-26 15:35 Zhentiw 阅读(25) 评论(0) 推荐(0)
摘要:https://www.npmjs.com/package/umzug // index.js const { Sequelize } = require('sequelize'); const { Umzug, SequelizeStorage } = require('umzug'); cons 阅读全文
posted @ 2023-02-05 01:35 Zhentiw 阅读(66) 评论(0) 推荐(0)
摘要:We use needleas a client on Node.js express server for fetching the data or site. https://www.npmjs.com/package/needle The leanest and most handsome H 阅读全文
posted @ 2023-02-05 01:32 Zhentiw 阅读(64) 评论(0) 推荐(0)
摘要:Express app: import cors from 'cors'; import express, { Application } from 'express'; import routes from './routes'; import * as middlewares from './m 阅读全文
posted @ 2023-02-05 01:07 Zhentiw 阅读(46) 评论(0) 推荐(0)
摘要:Creating a CLI in Node.js just takes a extra step or two because they are really just an ordinary Node.js app wrapped behind a bin command. For this e 阅读全文
posted @ 2022-09-02 22:09 Zhentiw 阅读(38) 评论(0) 推荐(0)
摘要:If you cannot catch those pesky errors for any reason. Maybe some lib is throwing them and you can't catch them. You can use: process.on('uncaughtExce 阅读全文
posted @ 2022-09-02 01:26 Zhentiw 阅读(19) 评论(0) 推荐(0)
摘要:CrudController: 查看代码 export const getOne = model => async (req, res) => { try { const doc = model .findOne({ createdBy: req.user._id, _id: req.params. 阅读全文
posted @ 2022-08-23 19:25 Zhentiw 阅读(29) 评论(0) 推荐(0)
摘要:Each model controller: import { crudControllers } from '../../utils/crud' import { Item } from './item.model' export default crudControllers(Item) You 阅读全文
posted @ 2022-08-23 19:23 Zhentiw 阅读(19) 评论(0) 推荐(0)
摘要:Model: import mongoose from 'mongoose' const itemSchema = new mongoose.Schema( { name: { type: String, required: true, trim: true, maxlength: 50 }, st 阅读全文
posted @ 2022-08-23 19:20 Zhentiw 阅读(18) 评论(0) 推荐(0)
摘要:Model: import mongoose from 'mongoose' const itemSchema = new mongoose.Schema( { name: { type: String, required: true, trim: true, maxlength: 50 }, st 阅读全文
posted @ 2022-08-22 21:00 Zhentiw 阅读(22) 评论(0) 推荐(0)
摘要:Example 1: import mongoose from 'mongoose' const itemSchema = new mongoose.Schema( { name: { type: String, required: true, trim: true, maxlength: 50 } 阅读全文
posted @ 2022-08-22 19:23 Zhentiw 阅读(55) 评论(0) 推荐(0)

1 2 3 4 5 ··· 10 下一页