Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Faker library now uses lower-case object name.

    Basic Server Setup for JWT Authentication

    Kent C. DoddsKent C. Dodds

    Creating the basic node server to serve up random users via API endpoints.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    Man 1: This is "Authentication with AngularJS, Getting it Right with JWT." That's pronounced "Jot".

    We're going to create a basic server that will server up a random user and then create a front end client that will consume this service to illustrate how to do authentication with JWTs.

    First of, we're going to need our JavaScript file. We'll call that Server js. A couple of things that we're going to need through NPNR, Express and Faker.

    Faker's how we're going to make the random user. We're going to require Express and we'll require Faker. Then we'll create our app. Then we'll have our app and have a get on random user with the request and response.

    We'll save our "User = faker.Helpers.userCard" and "user.avatar = faker.Image.avatar." Then we'll say response send back the user as JSON. Then I will have our app listen on port 3000. We'll just say, "App listening on localhost:3000."

    We're going to use nodemon to have our server automatically restart every time we make changes so nodemon server js.

    Here we'll go to local host:3000. Obviously we can't get a route but we can get random user. Here every time we refresh we have a random user.