Skip to main content

Posts

Showing posts with the label NodeJS

Passport Package for Authentication in NodeJS

I watched a video and learnt about the passport  package to handle the authentication and save the user data in MongoDB from Google. Passport is the middleware for NodeJS. It can be used to authenticate using a username and password, Facebook, Twitter, Google and more. It is simple to use and flexible. Steps to use passport package for google authentication: - install passport npm i passport passport-google-oauth20 --save I used the below code to handle the authentication.  1. This file has Google strategy to fetch the user's profile from user's Google profile and saving it in my MongoDB. passport.js const GoogleStrategy = require ( 'passport-google-oauth20' ); const User = require ( '../models/User' ); module . exports = function ( passport ) { passport . use ( new GoogleStrategy ({ clientID : process . env . GOOGLE_CLIENT_ID , clientSecret : process . env . GOOGLE_CLIENT_SECRET , callbackURL : '/auth/google/callbac...

"NodeJS Basics" Theory That You Should Know

To know better about NodeJS, you should know Javascript. So I start with Javascript Javascript is in top 3 language. JavaScript is developed on December 4, 1995. It was a client-side scripting language. So it was used only in browsers. Javascript uses  Javascript engine that is used by browsers to convert code into machine code. We have multiple JavaScript engines just like we have different browsers like Firefox, Chrome, internet explorer, edge etc. First JavaScript engine was SpiderMonkey developed by Netscape Communication by the creator of JavaScript Brendan Eich and it was developed in 10 days. Different browsers are using a different type of Javascript Engine:- Internet Explorer is using Chakra Firefox is using Spidermonkey Chrome is using V8 Microsoft Edge is rebuild using a chromium-based browser and now it is using V8 engine. Most Famous engine is now V8 Javascript engine because it is faster and can be used for mobile development...