随笔分类 - Node.js
摘要:server.js: import itemRouter from './resources/item/item.router' export const app = express() app.use('/api/item', itemRouter) item.router.js import {
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:There are a handful of ways you can read and write to the File System in Node.js. We will look at readFileSync, readFile, and a promise based version
阅读全文
摘要:Node.js projects have two ways that you can import and export code into different files. This is through CommonJS (CJS) and ECMAScript modules (ESM).
阅读全文
摘要:https://btholt.github.io/complete-intro-to-realtime/socketio https://btholt.github.io/complete-intro-to-realtime/intro-to-websockets Socket.io: FE: co
阅读全文
摘要:https://btholt.github.io/complete-intro-to-realtime/intro-to-http2-push long-running HTTP call HTTP2 PUSH FE: async function getNewMsgs() { let reader
阅读全文
摘要:Polling with setTimeout async function getNewMsgs() { let json; try { const res = await fetch("/poll"); json = await res.json(); } catch (e) { // back
阅读全文
摘要:We'll learn how to use Next.js API Routes to hide sensitive information from the clients. In this case, we're calling the JSON Placeholder API with a
阅读全文
摘要:We'll learn how to create a middleware function for next-connect. This middleware will work at the route level, for example, for every request that hi
阅读全文
摘要:We'll learn an alternative way of creating API routes using the next-connect package. next-connect gives us an alternative that would feel familiar to
阅读全文
摘要:Code: import {UnauthorizedError} from 'express-jwt' function errorMiddleware(error, req, res, next) { if (res.headersSent) { next(error) } else if (er
阅读全文
摘要:When dealing with `fs` library, the common problem you will meet is the path to file. Different envs may have different way to handle the path. The be
阅读全文
摘要:import fs from 'fs'; import Jimp = require('jimp'); // filterImageFromURL // helper function to download, filter, and save the filtered image locally
阅读全文
摘要:1. Shell - Linux/Mac Users For Unix/Linux/Mac operating systems, a shell is a command-line program that accepts users' commands and executes those com
阅读全文
摘要:ORMS allow us to easily switch to a different dialect of SQL (e.g. PostgreSQL, MySQL), without having to modify the code that interacts with the datab
阅读全文
摘要:Intro to Object-Relational Maps (ORM) We'll be using an ORM called Sequelize to manage the connection to our database. We'll cover the basics in this
阅读全文
摘要:Features and Modularity In this concept, we dive into splitting our code into logical "features". This is a way of describing modular programming wher
阅读全文
摘要:We have a Netflify serverless functions which requires following packages: "devDependencies": { "playwright-aws-lambda": "^0.4.0", "playwright-core":
阅读全文
摘要:Read Dependency Confusion: How I Hacked Into Apple, Microsoft and Dozens of Other Companies Yarn: yarn install –immutable --immutable-cache --checkcac
阅读全文