bundle nodejs lambda function

Background We have several Lambda functions serving traffic for internal and external APIs. They work pretty well after AWS introduced the V2N which removes the ENI creation time, cold start time is greatly reduce. We are looking at more ways to optimize that. Optimization One thing we want to do for this is reduce our…

Brotli vs Gzip nodejs

Brotli vs Gzip We initially use Brotli to compress our api response, as it is the newer algorithm and has better compression rate(20%) than gzip/deflate. However we found the runtime overhead of the brotli Compressor is significantly higher than gzip. below is the comparison from my node v14.2.0 runtime with the built in `zlib`, with…

debug nodejs in chrome

The new chrome ships with the about:inspect and a dedicated debugger for nodejs which is super cool! At least we do not have to rely solely on console.log() magic. To do that, run script with an additional flag: node –inspect myServer.js This should fire up the app and then go to a new tab and enter about:inspect. Then…

nodejs eventloop 和libuv

NodeJS and Chrome eventloop Node.js and Chrome do not use the same event loop implementation. Chrome/Chromium uses libevent, while node.js uses libuv. Node’s API provides a kind of asynchronous no-op, setImmediate. For that function, the “some operation” I’ve mention above is “do nothing”, after which an item is immediately added to the end of the…

require exports module in nodejs/requirejs/commonjs

What is a Module A module encapsulates related code into a single unit of code. When creating a module, this can be interpreted as moving all related functions into a file. Let’s illustrate this point with an example involving an application built with Node.js. Imagine that we created a file called greetings.js and it contains…

How bower works.

When I first looked into Bower, I wasn’t exactly sure how it fit in: it wasn’t just a JavaScript package manager, like Jam, and it wasn’t a module loader, like RequireJS. It calls itself a browser package manager, but what exactly does this mean? How’s that different from a JavaScript package manager? The main difference…

missing jwt options in token using nodejs jsonwebtoken

I am using jsonwebtoken to handle the token generation and verification on the server side. The way I did it is once user auth successfully, I sign the ‘user’ object directly to generate the token like this: var token = jwt.sign(user, secret.secretToken, {expiresInMinutes: 60, issuer: ‘cccg’, algorithm:’HS384′}); I found my token never expires. After debugging(you can…

deploy nodejs angularjs mongodb expressjs application to openshift

In my previous post, I described how to upload file using nodejs and angularjs. Now we are to deploy this MEAN stack app to openshift which is a very good cloud service provider offering 3 application deployment for free. You can even deploy Java web application to it using Tomcat/Mysql, part of which i mentioned…

nodejs log to file for multiple modules

There are several projects provide the ability to log to file for nodejs like log4js, winston etc. I picked winston for no specific reason. init setup is pretty simple, just follow what is written in Github. To make it be able to be shared by multiple modules, we need some tweaks. First we need a…

debug nodejs with nodemon and intellij

Noticed that if I run nodemon within intellij, I would not be able to debug any more inside intellij. Not sure what reason it is. If just run the nodejs, no problem. However once I add the ‘/usr/local/bin/nodemon’ into the Node parameters of the run config, the breakpoint would not work. solution To solve this…

authentication angular nodejs with JWT

Why use it? Here are some advantages of choosing JWT: Standard: JWT is becoming a standard, and there a multiple libraries for a lot of languages (Ruby, Java, Python, Node, Backbone). So the integration with your language or technology should be pretty easy. Cross-domain / CORS: Since the information is transmitted using an HTTP header, you are…