Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 959 of the free egghead.io lessons, plus get Angular 1.x content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Basic Server Setup for JWT Authentication

1:44 Angular 1.x lesson by

Faker library now uses lower-case object name.

var user = faker.helpers.userCard();
user.avatar = faker.image.avatar();

The library changed the signature of the faker object.

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

Get the Code Now
click to level up

Faker library now uses lower-case object name.

var user = faker.helpers.userCard();
user.avatar = faker.image.avatar();

The library changed the signature of the faker object.

egghead.io comment guidelines

Avatar
egghead.io

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

Avatar
Jon

How did you get the code highlighting in your JSON output?

In reply to egghead.io
Avatar
Kevo

I found that the 'case' has changed to lowercase on faker.Helpers and faker.Image.

The code as presented did not work for me until I changed it to:

var user = faker.helpers.userCard();
user.avatar = faker.image.avatar();

Avatar
Pavel

var user = faker.helpers.userCard();
user.avatar = faker.image.avatar();

Yeah, that helps! I think that needs to be mentioned somewhere in lesson

In reply to Kevo
Avatar
Aron Rodrigues

What editor are you using?

Avatar
Kent C.

In this video I'm using Webstorm, but I use Atom these days: https://github.com/kentcdodds/ama/issues/113

In reply to Aron Rodrigues

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.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?