Blog Logo

Subscribe

RSS Join our email newsletter

Ronnie Garcia
Ronnie has been developing websites since 2000 and is currently a development team lead at The Control Group.

Using PM2 to Manage Your NodeJS Processes

PM2 is a process manager for NodeJS. PM2 will restart your node processes if they crash and keep track of the number of restarts. You can also connect your processes to keymetrics.io so you can monitor remotely. Installing PM2 Install PM2 globally via NPM to use it. $ npm install…

Using LRU Cache in NodeJS

First of all, what is a cache? A cache is a place where frequently-accessed data is stored that can be quickly retrieved with little overhead. Cache is useful when you have a database-driven website that gets high amounts of traffic as it can help reduce the load on your database…

Use SugarJS to Make Your JS a Little Sweeter

From the SugarJS.com website: Sugar is a Javascript library that extends native objects with helpful methods. It is designed to be intuitive, unobtrusive, and let you do more with less code. I normally use Lodash (lodash.com) as my go-to library for useful JavaScript functions, but after discovering SugarJS,…

A Better Way to Reference Dependencies in NodeJS

Let's say you're writing a NodeJS application and you've created a library or module that you want to use in different places throughout your app. You don't want to register it with NPM because it isn't useful for anyone else since it's specific to your app. You also don't want…

Don't Forget Your Return Statements in NodeJS

Because NodeJS is non-blocking, you might be running code that wasn't intended. This is why return statements are important in your code. It's a simple mistake that many developers can make when transitioning to NodeJS from a different language. Let's say you have an endpoint like the one below... // A…

Using JSON.parse to Coerce Values to Their Proper Types When Posting a Form

The problem with posting values to an endpoint directly from an online form is that they sent as strings. This means you have to coerce the values to the proper type after they are submitted. An easy way to do this is by using a try...catch block and JSON.…

Not All NodeJS Code is Non-Blocking

Even though NodeJS is asynchronous in nature, you have to understand that all the code you write is not always non-blocking. Any function that is CPU-intensive or that waits for a return value before proceeding will block the current event loop. While the event loop is blocked, it cannot accept…

Viewing a Dynamically Generated ReQL Query

RethinkDB is perfect for building dynamic queries based off any number of special conditions or input. The difficult part is trying to debug a dynamic query when something goes wrong. An easy way to see your final query is to convert the entire thing to a string and log it…