Dec 19, 2017

Node.js: Sinon Stub and Passport Authenticate

In my last post, I spent some hours to create a stub to skip passport.authenticate method for REST API testing. So, I decided to write a separate post on the same. Before we get started, let’s take a look on how auth middleware is implemented:

Dec 18, 2017

Node.js: REST API Testing using Mocha, Sinon and Chai

In my recent post, I covered how to implement token based authentication using Passport, JWT and bcrypt. Let’s extend this post and look into testing REST APIs or server side methods in Node.js using Mocha, Chai and Sinon.

Mocha: It is a test runner to execute our tests.
keywords in code = Describe, It, before, after…etc

Chai: It is an assertion library and allows to write code like writing regular english.
keywords in code = should, assert..etc.

Sinon: It provides test spies (fake functions to track executions), stubs (replace functions with our fake implementation) and mocks (predefined fake method with behaviour).

Dec 18, 2017

JavaScript: Null vs Undefined vs Undeclared

For a beginner, it is painful to understand two distinct things null & undefined in JavaScript and use them properly. I noticed many people consider and treat undeclared variable as undefined which is wrong perception. In this article, we will go through null, undefined, empty, NaN and undeclared variables and see how to handle them in different conditions.

Dec 17, 2017

Token Based Authentication with Node.js, Express, Mongoose and Passport

This tutorial explains how to implement REST API and Token based authentication in Node.js, Express, Mongoose environment. We are going to use JWT (JSON Web Token) + bcrypt (password hashing algo)+ Passport (authentication middleware to integrate different login strategies) combination. So jsonwebtoken, bcrypt-nodejs and passport-jwt javascript libraries will be used. It is assumed you are familiar with Node.js, MongoDB and ES6 basics.

Dec 2, 2017

How to Load Disqus Comments on Click

On searching Google, I got many articles on this but didn’t find any way to do if official Disqus comment system WordPress plugin is used. So, decided to write on it. This post explains how to setup Disqus on your website to load on-demand (on click on any button or link) and not automatically. It is assumed you’ve registered your website with Disqus before get started.