...

/

Project Setup: Part One

Project Setup: Part One

Understand the project's dependencies and files before beginning to work with Passport.js.

Task 1: Install dependencies

  1. Navigate to the project folder.

  2. Install the following dependencies:

    • bcrypt
    • express
    • jsonwebtoken
    • passport
    • passport-jwt
    • dotenv
Press + to interact
npm install --save bcrypt express jsonwebtoken passport passport-jwt dotenv

Task 2: Set up files for user authentication routes

  1. In the previous chapter, we set up a router, controller, and service for the recipes resource in the Express Recipes API. Let’s follow a similar pattern to organize our user authentication logic:
Press + to interact
touch src/routers/users.js src/services/users.js db/users.json src/controllers/users.js
  1. Create a new folder to store middleware functions. Within it, create a file called auth.js:
Press + to interact
mkdir src/middleware
touch src/middleware/auth.js

Later on, we’ll configure the Passport.js strategy inside src/middleware/auth.js.

  1. We’ll store the users’ data indb/users.json.

Note: This isn’t a robust database solution since there’s no built-in data validation, but it’s sufficient for demonstration purposes. ...