JWT - Why we don't need to store tokens in database?

I discussed a question with many people and the question was - Do you store the JWT tokens in the database?

First Answer:   Yes, we do store. Whenever we got an API call we get the token from the header and match it with the tokens that we have stored in DB.

Second Answer: No, we don't store tokens in a database we simply get them verified by JWT itself. We get the token from the header and pass it JWT verify method like jwt.verify(token, secret).

What I feel is that it is not required to store the tokens in the database. Because if you will be storing tokens in the database then you'll be setting some TTL(expiry time) there and on every request you will be verifying the token with user requested token and every time you'll update the TTL. ...  Read More

Share This:


How to use Typescript with Node.js | Building a Node.js App with TypeScript

If you are using Javascript to build your application it's fine if that is a small application but once your application becomes big, it's really hard to manage the code quality.

To write the manageable and typed Javascript we started using Typescript. Typescript is just the superset of Javascript which is strictly typed.

The issue with Typescript is, it can't simply run on the browser or V8 engine. We need to transpile the Typescript to Javascript. Here in this article, we are going to use TSC to transpile the Typescript to Javascript. ...  Read More

Share This:


Node.js & Redis App | Search user in Node.js and Redis | Register user in Redis database in Node.js | Delete user from Redis database in Node.js

Many of the applications use Redis for improving the application performance. Redis is not only used for the caching purpose. Redis supports many of the data types. Redis also support publish and subscription functionality. We can cluster the Redis database. Redis serve as in-memory, key-value data stores, although Redis is more accurately described as a data structure store.



Here in this article I'm going to use Redis with Node.js. I'll register the user in Redis database by using hmset command. I'm assuming that you have installed Redis, Node.js and NPM on you machine. ...  Read More

Share This:


Real time commenting System with Node and MongoDB | Real time commenting on post using Node.js and Socket.io

Nodejs comment system example

Nodejs comment system example

So many applications required real time programming and believe me Node.js and Socket.io is the best combination or that. So many applications required real time commenting system. Today in this article you are going to learn how you can comment in real time in Node.Js by using Socket.io.

In my previous Node.js tutorial I explained video streaming in Node.js with the help of socket.io.
Today also I'm going to use socket.io for creating the real time comment system in node.js.

I'll create a simple commenting system. There will be a listing of posts. I'll be fetching the posts from MongoDB. You also will be able to view detail of every post. On detail page of posts you could comment in real time. I'm also saving your comments in MongoDB along with real time commenting. So whenever you'll see the post detail you could see the comments. ...  Read More

Share This:


Video stream with Node.js & Socket.io | Stream data in Node.js using Socket.io

video-streaming-node-js-example

Video streaming example in Node.js || Socket.io

Let me tell you one thing that real time video streaming in Node.js is super simple. When the question comes in our mind to stream data we think Ohhh.. this is very big task and you overhead yourself.

In this article I'll explain you that you can stream your data with few lines of code by using sockets.

I'll be using socket library to stream the data in real time. I also will be using express module for just to manage my routes and to defining my static directories.

I'm assuming that you have installed Node.js and NPM at your system. ...  Read More

Share This:


CRUD operation in Node, Express Js and Mongoose | Node Js CRUD tutorial

In most of the applications we do the same thing and that CRUD (Create, Read, Update and Delete). Today we are going to do the same but in Node Js where we are using MongoDB as a database.                   

If you wanted to start with Node Js believe me this article will make you life very easy in Node Js & Mongo DB.

Before starting I believe you installed Node Js, NPM, Express and MongoDB.

Here is the video where I have discussed the below functionality.

The below link will help you for creating a Node Js App. ...  Read More

Share This:


Middleware in Node Js & Express | How to create authentication Middleware in Node Js & Express

Express is an routing and middleware framework. And we use express to managing the routes and middlewares. Also it provides some folder structures.

Middleware is something which you wanted to execute before executing any particular function. For example we need a login check before accessing the user  dashboard and logout. That check is called middleware here.

In Express framework middleware has access to req (Request), res (Response) and next (Next route).

We validate the data through the request and if validation is true then return to the next action else we return to any URL like login using res (Response). ...  Read More

Share This:


Send message on redirect in node js | redirect with message node js | Flash message in node js

Some time we need to print a message after the redirection of page.
Like when you delete a post and will show “Post deleted successfully!” after reloading or redirecting the page.
I’m going to explain how we can redirect to another page in node js along with message.
First you need to install  express-session using below command if you have not installed:

Now you need to install req-flash using below command. It flash the message but this library is dependent on session.

Now in app.js include following:

If you are using express js might be you don’t need to put this line because this is already there.

Now you need to use session if you have not used it in app.js yet:

Now use flash in app.js file:

Now you can put your message in following way :

and you can achieve the message by following code.

so you can render your messages to view like this

Now on view you can print the message like :

Here I’m using ejs template engine. ...  Read More

Share This:


Restful apis in Node Js with Mongo DB | Developing web services in Node Js & Mongo DB

In this tutorial I'm going to explain how to develop restful apis node jsI will be using MongoDB as database. I will be explaining simple apis which can add,fetch all, fetch by id, delete or destroy and update the records.

To start with we need to install mongoose by following command if we have not installed it yet.

To install the mongoose:                                                                                                                        

Here is the post route which contains all functions add,fetch all, fetch by id, delete or destroy and update the records. ...  Read More

Share This: