随笔分类 -  Node.js

1 2 3 4 5 ··· 10 下一页
摘要: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 阅读(10) 评论(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 阅读(4) 评论(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 阅读(6) 评论(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 阅读(34) 评论(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 阅读(8) 评论(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 阅读(11) 评论(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 阅读(14) 评论(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 阅读(60) 评论(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 阅读(49) 评论(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 阅读(25) 评论(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 阅读(25) 评论(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 阅读(10) 评论(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 阅读(21) 评论(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 阅读(11) 评论(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 阅读(13) 评论(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 阅读(15) 评论(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 阅读(40) 评论(0) 推荐(0) 编辑
摘要:server.js: import itemRouter from './resources/item/item.router' export const app = express() app.use('/api/item', itemRouter) item.router.js import { 阅读全文
posted @ 2022-08-22 19:14 Zhentiw 阅读(13) 评论(0) 推荐(0) 编辑
摘要:Add to global commands Add #! /usr/bin/env node to index.js chmod +x index.js Run ./index.js to test. ln -s <full_path_to_index.js_file>/index.js /usr 阅读全文
posted @ 2022-08-05 21:01 Zhentiw 阅读(18) 评论(0) 推荐(0) 编辑
摘要:Our CLI can be run from anywhere on the system but we have a critical error. The script is trying to find a data.json file that is relative to where i 阅读全文
posted @ 2022-08-05 20:57 Zhentiw 阅读(77) 评论(0) 推荐(0) 编辑

1 2 3 4 5 ··· 10 下一页
点击右上角即可分享
微信分享提示