Getting Started with Passport
An advantage of NodeJS is that there is a ton of available software. Probably more software libraries are available for NodeJS than any platform. One of those libraries is Passport, which can be used to handle authentication.
Getting Passport set up and running isn’t difficult but does require a few steps. First, we must install Passport.
Import some node modules.
npm install passport npm install passport-local
Import the Passport libraries.
Now we need a strategy; in this case, we will create a very simple authentication strategy. It’s so simple that it should only be done in a demo: the password is “password”. Never do this in a production-level solution.
Now must initialize Passport.
The last step is writing an HTTP handler for an authentication request.
We now have a very simple user/pass authentication using Passport.