Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun.

We often use environment variables in our code(modules) and when testing code it should be available at run time. In this post, I will show you a few nice ways to pass environment variables to Mocha test cases. You can choose one suits your need best.

Using `- -require (-r)` option

Mocha provides you rich set of CLI options. You can use the --require (-r) command-line option to preload dotenv . In your package.json file use this test command:

"scripts": {
"test": "mocha tests/**/*.js …

Reading or writing a file in Deno is super easy. Deno provides both sync and async APIs for the file operations. This article will cover the basic read and write functionality for a file.

As you would know Deno is a secure runtime for JavaScript and typescript, so to read and write a file the program needs explicit permissions. We can enable file reading with the --allow-read and write permission with --allow-write

Reading a file:

If you simply want to read a file as a text string you can use



Deno’s readTextFile the method returns a Promise that resolves to a utf8…

Deno 1.0.0 was released in May 2020. It Has built-in utilities like a dependency inspector (deno info), a code formatter (deno fmt), debugger, and Test runner. It also supports top-level await.

But Deno has been around only for 2 years now so a number of third party libraries are very less as compared to NPM repository. But don’t worry, If you are looking for a library that is not available at yet, Thanks to Deno, you can still run some npm packages in Deno.

Deno provides a Node compatibility layer, that will allow us to use some NPM packages…

Sometimes there are use cases when we have to call third party services (APIs) where cors are not allowed or only enabled for production or have to be dependent on a third party for it. In this post, I will discuss how cors works and then will create a basic cors proxy in Node as a workaround for the cases I have mentioned.

Before writing a Cors proxy it is important to understand how cors works. So let’s get started.


When you run a web server you can not access images, APIs, etc from different servers if CORS is not…

Image courtesy:

In order to write performant and clean code, one should understand the working of language(or platform) and its design principles and patterns. In this post, I will list a few common points that every Nodejs developer should know which will ultimately help you write better-performing code.

There are a few things below you should learn and understand as much as you can. This will give you good knowledge of the Nodejs event loop and will help you understand this post better.

  • To know how Nodejs the Event loop works.
  • To know the differences between CPU intensive vs IO intensive tasks.

Quickly set up Https for localhost

In this blog post, I will show you how to set up working HTTPS with a green lock mark.

Steps to Generate Working SSL certificate For Localhost:

  • Create a Root SSL certificate for localhost.
  • Make Root Certificate be trusted by System.
  • Issue a domain certificate by Root certificate we created in the first step.

If you don’t want to do all these steps then check this out

Before getting into the detail of each step, let’s talk about a few terminologies:

Root Certificate: A Root SSL certificate is a certificate issued by a trusted certificate authority (CA).

The SSL…

In 2019, Node.js turned 10 years old, and the number of packages available on npm crossed one million. Downloads for Node.js itself continues to rise, growing 40% year over year. Another significant milestone is Node.js recently joined the OpenJS Foundation, which promises to improve project health and sustainability, as well as improve collaboration with the JavaScript community at large.

Nodejs v12 is in LTS since October 2019, comes with a few good features and improvements.

You might be aware that Nodejs v12(Erbium) now has LTS since 2019–10–21 with awesome features and improvement. And you might not want to miss these…

Workers Threads Examples In Node.js

In part1, I have covered:

  • What are the worker threads?
  • How are they different?
  • Why and When to use worker threads.

In this article, I will cover some use cases and a few coding examples.

Note: You can directly jump down for the example code.

If you have not read the previous post yet, I would recommend reading the first part of this article. Before continuing with this article let’s recall a few points from the previous post.

  1. Don’t block the event loop, keep it running and avoid anything that could block the thread-like synchronous…

Workers Threads In Node.js (Overview)

Workers thread were introduced in Node v10.x as an experimental API and now stable since v12.x. As we all know Nodejs single-threaded(Though it has Libuv thread pool) model is well suited for non-blocking IO operation. But Node.js shows poor performance when it runs CPU intensive (blocking code) because Node executes blocking code in the main thread and blocks other code for execution. The main purpose of this post is to cover:

  • Overview of worker threads.
  • How are they different than normal threads?
  • Why and when to use worker threads?

CPU Intensive tasks

What happens if we need to do synchronous intense stuff? Such…

Sandeep Patel

Software Developer Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store