1
00:00:00,330 --> 00:00:07,020
And when it comes to express right limit, we have few options if you want, you can set it up for the

2
00:00:07,020 --> 00:00:08,760
entire application.

3
00:00:09,300 --> 00:00:14,670
And basically, the syntax would be something like this where you grab the package.

4
00:00:14,670 --> 00:00:19,890
So express rate limit set up some kind of variable and then you want to invoke it.

5
00:00:20,530 --> 00:00:23,970
And in now you pass in the object with the properties.

6
00:00:24,090 --> 00:00:30,180
So and here are the two most important ones are how many requests in how long.

7
00:00:31,080 --> 00:00:36,960
So if you want to go with 100 requests per 15 minutes, this is the code.

8
00:00:37,380 --> 00:00:42,990
And essentially they set it up like this because one second is thousand milliseconds.

9
00:00:43,590 --> 00:00:48,900
So this is going to be one minute and then times 15, this is going to be 15 minutes.

10
00:00:49,230 --> 00:00:52,320
So of course, if you want to change that power, that is up to you.

11
00:00:52,530 --> 00:00:58,710
And again, how many requests per that time in this case, 15 minutes.

12
00:00:59,010 --> 00:01:01,670
And then you just set it up over here, notice.

13
00:01:01,740 --> 00:01:02,760
You don't need to invoke it.

14
00:01:03,030 --> 00:01:08,910
Just assign it to a variable and you push it in the middle where again, I'm not yours.

15
00:01:08,970 --> 00:01:10,890
And you can definitely do so in the server.

16
00:01:11,250 --> 00:01:15,440
So essentially, just like we set up rush stuff the libraries.

17
00:01:15,450 --> 00:01:21,510
However, in this case, I'll show you the alternative where we can add it just for specific out.

18
00:01:22,450 --> 00:01:27,310
And in my case, I'm going to add it only to register and log in.

19
00:01:27,760 --> 00:01:28,180
That's it.

20
00:01:28,300 --> 00:01:32,880
Again, let me repeat, if you want to set it up for your entire application, you can definitely do

21
00:01:32,890 --> 00:01:33,130
show.

22
00:01:33,610 --> 00:01:36,970
But in my case, I'm only going to add it to two rounds.

23
00:01:37,300 --> 00:01:39,400
So let me navigate back to my application.

24
00:01:39,820 --> 00:01:43,870
I'm looking for routes folder one specifically all throughout.

25
00:01:44,170 --> 00:01:48,310
And the first thing that I want to do is grab that rate limiter.

26
00:01:48,640 --> 00:01:50,410
So that's the variable I'll set up.

27
00:01:50,420 --> 00:01:59,050
So rate and then limit are not as equal from a we go with express and rate limit one.

28
00:01:59,290 --> 00:02:01,910
Once we have that one place and set up the variable.

29
00:02:01,930 --> 00:02:08,320
So in my case, that's going to be API limits are not as equal to rate limiter.

30
00:02:09,280 --> 00:02:10,389
Let's pass in the object.

31
00:02:10,630 --> 00:02:17,740
And in my case, I'm going to go with window and seconds and I'm going to keep the same pattern basically

32
00:02:17,740 --> 00:02:23,650
15 minutes or 15 times 60 times a thousand.

33
00:02:23,770 --> 00:02:29,710
And I don't think that I need to repeat why we use these numbers, and I'll just add a comma here and

34
00:02:29,710 --> 00:02:32,980
also accept the comment 15 minutes.

35
00:02:33,490 --> 00:02:36,580
Now I also want to add how many requests.

36
00:02:37,610 --> 00:02:39,080
And in my case, I'm going to go with them.

37
00:02:39,980 --> 00:02:46,070
So in 15 minutes, Max, you can have 10 requests from that IP address.

38
00:02:46,520 --> 00:02:48,680
And lastly, we can set up the custom message.

39
00:02:49,100 --> 00:02:54,710
So just to showcase that we can go with message property and I'm going to go to many requests from this

40
00:02:54,710 --> 00:02:55,190
IP.

41
00:02:55,560 --> 00:02:58,850
Please try again after 15 minutes.

42
00:02:59,210 --> 00:03:08,000
And once that is in place now, we just want to take this API limiter and place it in the round where

43
00:03:08,000 --> 00:03:08,720
we want to use it.

44
00:03:09,140 --> 00:03:13,850
So in my case, that is going to be for register and log in.

45
00:03:14,270 --> 00:03:22,310
So let's go over here, say API limiter, comma, and the same thing is going to be over here for too

46
00:03:22,310 --> 00:03:28,010
long an API limiter and we're going to go now for these two are out.

47
00:03:28,490 --> 00:03:38,330
There's going to be a fan request max in 15 minutes and once that is exceeded, then we get back the

48
00:03:38,330 --> 00:03:38,990
error message.

