随笔分类 - Node.js
摘要:In this lesson we'll build a basic web server in 2 minutes using Express 5 and node 14's native ES module support. We'll start by creating a new proje
阅读全文
摘要:When express App run syncronous code: app.get("/test", (req, res) => { throw new Error("Oh no! The world has ended!"); }); Those code works fine. But
阅读全文
摘要:Mirage JS lets you mock out production APIs directly alongside your frontend React code. You can tweak the data or force a network request to hang, so
阅读全文
摘要:In package.json file: "prepare": "npm run build", "postpublish": "git push --tags", "prepare": make sure we don't forget to run build before publish t
阅读全文
摘要:For example we have a rest endpoint, we need to validate the data we receive in correct format: import { IsMongoId, IsString, IsBoolean, IsInt } from
阅读全文
摘要:Fallback exception filter is mean to catch any exception which are not catched by other exception filters; main.ts: Order matters, from most generic t
阅读全文
摘要:Throw expection from Controller: Expection types: https://docs.nestjs.com/exception-filters#built-in-http-exceptions We can create global reuseable ex
阅读全文
摘要:main.ts Module: Schema: Controller: Repository:
阅读全文
摘要:Before we publish our package, we want to make sure everything is set up correctly. We’ll cover versioning, preparing our package, adding a proper REA
阅读全文
摘要:For example we have a function to check the filesize: It works fine, but the 'fileSize' function has a problem, those part of code run in sync, not as
阅读全文
摘要:We will see how you can use npx to pull and execute code from a GitHub repository. If you need even more control, you can target a specific branch of
阅读全文
摘要:We will incorporate npm specific environment variables when executing various npx commands. In our example, we will transpile code to a folder name th
阅读全文
摘要:We will use npx to run a package using different versions of Node.js. This can become valuable when testing the various new features that are introduc
阅读全文
摘要:We can using gzip and crypto with stream: Also unzip it:
阅读全文
摘要:Node.js come alone with many Stream API. Stream is useful when handling large trunck of data. For example, we have a big file to read from file system
阅读全文
摘要:For example you have a server.js file, and you want to debug some problems; What you can do is: Then go to chrome broswer: You will find node.js targe
阅读全文
摘要:It might be possible for our node server has some downtime, no matter it is because server update or simply some crashs in the code. We want to minizi
阅读全文
摘要:Let's see how to do load balancing in Node.js. Before we start with the solution, you can do a test to see the ability concurrent requests your curren
阅读全文
摘要:When build server, if we have a API endpoint requires some heavy calculation process, it will block the whole world. In this post, we will see how to
阅读全文
摘要:Creating Markdown files from a template is a straightforward process with Node.js and Mustache. You can define a template, load it into your script, t
阅读全文