10 Best Practices for Writing Node.js REST APIs


This post from: https://blog.risingstack.com/10-best-practices-for-writing-node-js-rest-apis/ In this article we cover best practices for writing Node.js REST APIs, including topics like naming your routes, authentication, black-box testing & using proper cache headers for these resources. One of the most popular use-cases for Node.js is to write RESTful APIs using it. Still, while we help our customers to find … Continue reading 10 Best Practices for Writing Node.js REST APIs

(Node js) Prevent lost session context node-continuation-local-storage in Promise


This topic maybe too old but it will help you understand more about scope and lifetime of variable in node js: http://blog.mixu.net/2011/02/03/javascript-node-js-and-for-loops/ And in the previous topic: I have been mention about "node-continuation-local-storage" https://quangphamsoft.wordpress.com/2017/07/03/node-js-preserving-data-across-async-callbacks-with-continuation-local-storage-and-mongodb-client/ When we start session for each request with: Sometime we need to define some Promise to handler another purpose like this: … Continue reading (Node js) Prevent lost session context node-continuation-local-storage in Promise

Manage each request session in node js to authentication or anything


In this post, I'm using node-continuation-local-storage  to manage session per each request to server node js. Step1: Install it Step2: Init session in middleware in route of node js public static authentication(req: express.Request, res: express.Response, next : Function) { let token = req.headers['x-access-token']; // decode token if (token) { // verifies secret and checks exp ... session.run(() => … Continue reading Manage each request session in node js to authentication or anything

Node js – Preserving Data Across Async Callbacks in continuation-local-storage and MongoDB client


The problem when we use a lot of promises to handle callback in node js it will be destroyed variable "process.domain" in callback context when using it in the wrong way. To more details of this problem you can read this post: https://datahero.com/blog/2014/05/22/node-js-preserving-data-across-async-callbacks/ The Problem The ability to track a single request by a transaction id … Continue reading Node js – Preserving Data Across Async Callbacks in continuation-local-storage and MongoDB client

Angular 2/4: Resolved poblem with Error encountered resolving symbol values statically. Calling function ‘ɵmakeDecorator’


Porblem when try to build on server with : "build:prod": "ng build --prod"   Error encountered resolving symbol values statically. Calling function 'ɵmakeDecorator', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol Injectable in@angular/core/core.d.ts, resolving symbol ɵf in @angular/core/core.d.ts, resolving symbol ɵf in @angular/core/core.d.ts … Continue reading Angular 2/4: Resolved poblem with Error encountered resolving symbol values statically. Calling function ‘ɵmakeDecorator’

Argument of type ‘HttpStatus’ is not assignable to parameter of type ‘(resolve: (value?: {} | Thenable) => void, reject: (reason?: any) => void) => any’. Type ‘HttpStatus’ provides no match for the signature ‘(resolve: (value?: {} | Thenable) => void, reject: (reason?: any) => void): any’.


Two way to resolved this problem: Change index.d.ts function resolve<T>(value?: T | Thenable<T>): Promise<T>; This is a bad type definition. It makes the claim that for any type T, you can call the function with 0 arguments, and get a promise that resolves to T. Which is: generally not what one intends by calling Promise.resolve() … Continue reading Argument of type ‘HttpStatus’ is not assignable to parameter of type ‘(resolve: (value?: {} | Thenable) => void, reject: (reason?: any) => void) => any’. Type ‘HttpStatus’ provides no match for the signature ‘(resolve: (value?: {} | Thenable) => void, reject: (reason?: any) => void): any’.