Learn Node JS in 40 Minutes (Crash Course) - Express, CRUD APIs, etc — Transcript
Full transcript
- 0:00Every back-end job description starts
- 0:02with one requirement, Node.js. And by
- 0:04the end of this course, you'll build a
- 0:06complete job tracker API while learning
- 0:08Express, REST APIs, routing, middleware,
- 0:12CRUD operations, and everything that you
- 0:14need to get started with back-end
- 0:15development. So, first of all, what the
- 0:18hell is Node.js? So, I have opened this
- 0:20browser right here. And as you already
- 0:22know, JavaScript is meant to run on
- 0:24browsers, right? So, if I write
- 0:26console.log,
- 0:27and I'm going to say subscribe to
- 0:28Roadside Coder and press enter, and
- 0:30you'll obviously see that we will get
- 0:31the output over here. That's completely
- 0:33normal. But, what if we take this code
- 0:35right here and go to our VS Code and try
- 0:37to run this same code right here? We
- 0:39will have to do something like node
- 0:41>> [music]
- 0:41>> and then the name of the file. So,
- 0:42index.js.
- 0:44And you can see that this runs. And this
- 0:47is made possible using Node.js. And that
- 0:49is because Node.js is built on V8 engine
- 0:53that Chrome runs on. And that is what
- 0:55allows it to run outside of the browser.
- 0:57It can read and write files, run
- 0:59servers, talk to databases, build CLI
- 1:01tools, and much more. And we will cover
- 1:03all of these things in this course
- 1:05itself. And by the way, guys, I've
- 1:06created this complete Node.js cheat
- 1:08sheet. So, if you want the link to these
- 1:09slides, let me know in the comments down
- 1:11below and I'll send you the link. All
- 1:12right. Now, first thing's first, we need
- 1:13to install Node.js. Yes, Node.js is
- 1:16something that you need to install
- 1:17inside of your computer. Open this
- 1:18nodejs.org website. Click on get
- 1:21Node.js. And depending on your platform,
- 1:23like for example, if I'm on Windows, it
- 1:25shows me Windows installer right here.
- 1:27So, I'm going to click on that and just
- 1:28save it and you can install it. I
- 1:29already installed it, so I don't need to
- 1:31install it anymore. And once you have
- 1:32done that, you can open any of your
- 1:34favorite code editor and just come to
- 1:36the terminal and just say node {dash} v,
- 1:39and you will see the version of the node
- 1:41installed inside of your computer. All
- 1:43right. Now, before moving forward, I
- 1:44want you guys to understand a very
- 1:46important concept of event loop. So,
- 1:48see, I have this code right here.
- 1:50Console log order. Then we have set
- 1:52timeout, which will console log cook, or
- 1:55we can also say cooking. And then, we
- 1:57will have console log next short. So,
- 1:58what do you think is going to be the
- 1:59output of this? So, let's try to run it.
- 2:02And we say node index.js, and you can
- 2:04see it first printed order, then next
- 2:07order, and then the cooking at the end.
- 2:10And this is because JavaScript does not
- 2:12wait for anything. And by the way, this
- 2:14is a very important interview question
- 2:15as well that I've discussed in my
- 2:16interview preparation course as well, so
- 2:17you can check that from the link in the
- 2:18description down below. So, basically
- 2:20JavaScript is a single-threaded
- 2:22language. So, it cannot wait for the set
- 2:25timeout to get finished, right? Even if
- 2:27it's 0 ms, this will be executed at the
- 2:30very end. Let me explain you in a better
- 2:32way with an example. So, let's say we
- 2:33have a chef who is working on a
- 2:34restaurant, and he receives an order,
- 2:37right? So, that is an instant operation.
- 2:39So, console.log order, that will be
- 2:40printed. But, he will start cooking that
- 2:44particular order in the background,
- 2:46right? And meanwhile, waiter will go on
- 2:49and bring another order. So, that order
- 2:51will be printed instantly. The chef will
- 2:53not wait for the previous
- 2:55order to be cooked and then receive the
- 2:57next order, right? He can start working
- 2:59on those orders asynchronously, right?
- 3:01So, but as soon as that particular order
- 3:03is cooked, we can console.log cook
- 3:05operation as well, right? So, similarly,
- 3:08JavaScript works the same way. It works
- 3:11on the synchronous actions first and
- 3:13then picks up the asynchronous operation
- 3:15at the very end. So, you can see the
- 3:17cooking was printed at the very end.
- 3:19Okay. So, now how do we go on and create
- 3:22our very first Node.js project? We will
- 3:25use something called as NPM, Node
- 3:27Package Manager. And Node.js comes
- 3:29bundled with this NPM. So, I'm going to
- 3:32go to my terminal, and I'm going to say
- 3:33NPM init, and press enter. And it's
- 3:36going to be asking me the name of my
- 3:38package. So, I'm going to press enter.
- 3:39Let's keep it this.
- 3:41Version one, description if you want you
- 3:43can enter it. Entry point can be
- 3:44index.js. Yes, we have already created
- 3:46it. Test command, we don't need to do
- 3:48that. Get repository, keywords, we can
- 3:50keep all of these empty for now. Now,
- 3:52type is something that is very
- 3:53important. So, we will keep it common js
- 3:55for this video to keep it very simple
- 3:57and you'll notice that this will
- 3:58generate something called as a
- 4:00package.json
- 4:02file right here, right? With all of
- 4:03these details that you have entered.
- 4:05Now, whenever we install a new package,
- 4:07it will show up right here. Like for
- 4:09example, I'm going to say npm install
- 4:11express. Now, express is basically a
- 4:14framework which is built on top of node
- 4:16js. We will explore that as well later
- 4:18in this video. So, you will see that we
- 4:20will have this express as a part of
- 4:22dependencies right here. We will also be
- 4:25installing something called as nodemon,
- 4:28which is going to be used to restart our
- 4:30server basically whenever we make any
- 4:32changes inside of the index.js file. So,
- 4:35that we don't have to do, you know, node
- 4:37index.js again and again. So, see, what
- 4:39I'll do right here in the scripts, you
- 4:42don't need this test script. I will be
- 4:44adding a dev script over here and I'll
- 4:46say nodemon and you can write the name
- 4:49of your file. index.js
- 4:51right here. Let me just run it. So, I'll
- 4:53say npm run dev. There we go. It is
- 4:56running. Now, if I go to index.js, let's
- 4:58bring back that code. If I just save it,
- 5:00now you can see it has restarted our
- 5:03server and it has printed this file,
- 5:05right? So, this is super helpful. Cool.
- 5:06Now, let's go on and understand some of
- 5:08the core modules of node js. So, first
- 5:10of all, let's discuss the fs and path
- 5:13modules. So, fs basically allows us to
- 5:15read and write files using node js and
- 5:18path basically helps us generate the
- 5:20path to that particular file
- 5:22that we're trying to read and write. Let
- 5:23me show you. So, let's create a new file
- 5:25right here called data.json
- 5:28and I'm going to put some dummy data
- 5:30inside of it. If you want, you can do
- 5:31that as well. Let's just make this data
- 5:33smaller so you guys can copy it up if
- 5:35you want. So, I've put this data over
- 5:38here and now I'm going to go back to
- 5:39index.js
- 5:41and I'll first of all import the fs
- 5:42modules. So, while we are we were
- 5:44creating the app, there was option to
- 5:45select uh common js, right? So,
- 5:47basically there are two ways to import
- 5:49something in Node.js. So, you can do
- 5:52const fs
- 5:54= require, and then the name of the
- 5:57package. So, we have installed two
- 5:58packages right here, Express and
- 6:00Nodemon. So, we can choose that.
- 6:02Otherwise, we can choose the inbuilt fs
- 6:04package inside of Node.js. And if you
- 6:06want to import it something like this,
- 6:09import fs from
- 6:12fs, which won't work right now. So, you
- 6:13can see this is crashing. All we have to
- 6:15do is change this common JS to module
- 6:18right here, right? But to keep things
- 6:20simple, as I mentioned, we will use
- 6:22common JS in this video.
- 6:24Let's get rid of this. We will also be
- 6:26importing the path module inside of this
- 6:29file from Node.js. And now, let's get
- 6:31the path to this data.json file. So, we
- 6:34will say path
- 6:36.join.
- 6:38And here, we want to first full target
- 6:40the current directory. So, it will be
- 6:42__dirname,
- 6:45and then the name of the file that we
- 6:46want to reach. So, this path to some
- 6:49variable like file path.
- 6:54Right? Now, if you want to read the
- 6:56contents inside of this data.json file,
- 6:58we have two ways by using this fs. First
- 7:01is the synchronous way, which, you know,
- 7:03blocks the thread and the flow of our
- 7:05code. And second one is asynchronous,
- 7:07which is generally preferred in the real
- 7:09apps. So, I'll say fs
- 7:11.readFileSync.
- 7:13That is, read file synchronous. I'll
- 7:15provide it the file path that we have
- 7:17taken. So, you can see we are providing
- 7:19the path, and then it takes the options
- 7:21right here.
- 7:23So, I'm going to provide UTF-8.
- 7:25So, this will return us the content of
- 7:28our file. So, I'll just save it inside
- 7:29of this data variable. Okay, let's see.
- 7:33How about we go on and console log this?
- 7:34So, I'll just say console log
- 7:37this data over here, and let's go and
- 7:39check our terminal. Yep, you can see
- 7:42this data right here. Awesome. Now,
- 7:44let's try doing this again, but in a
- 7:47asynchronous way. So, instead of read
- 7:49file sync,
- 7:51I'll simply say read file right here.
- 7:54We'll provide the file path, UTF-8 type,
- 7:56and then we can also provide it with a
- 7:59callback right here. We will get the
- 8:01error over here if there's any error,
- 8:03and the data that we will get from it.
- 8:05And actually, we don't need this
- 8:07constant data now. So, if there's any
- 8:09error, we can throw that error right
- 8:10here. Otherwise, we can simply console
- 8:12log the data. So, I'll just comment this
- 8:14out. Let's save this again. And yep, we
- 8:16can see right here. Awesome. Like let's
- 8:19change the name of this file, and you
- 8:21will see that we get this error right
- 8:23here, right? Because we have checked if
- 8:25there's any error, then throw the error.
- 8:27Awesome. So, this asynchronous version
- 8:29basically exists for scripting and
- 8:31tooling, but in a real server, you will
- 8:33want to prefer this asynchronous method
- 8:35so that you don't block the other
- 8:37requests. All right. Now, how do you go
- 8:39on and write inside of a file, right?
- 8:41This one is for reading, but how do you
- 8:43write it? So, I'll just get rid of all
- 8:45of this code right here, and I'll take a
- 8:47new data over here, right? With this
- 8:49application, this application, like
- 8:51three applications right here. I'll just
- 8:52shrink it right here. Now, we want to
- 8:54replace this file data with our new
- 8:57data. So, to write inside of this file,
- 8:59I'll say fs. write
- 9:02file. And this also has write file
- 9:04asynchronous and synchronous. Again, we
- 9:06will prefer the asynchronous version
- 9:08over here. I'll provide it with the file
- 9:10path, and then I'll provide it with the
- 9:12data. So, I'll say JSON.stringify
- 9:14to convert the object into a string.
- 9:17I'll provide it with the new data, and
- 9:19you'll see it takes the value first. If
- 9:21there's any replacer, right? Like key or
- 9:24value, anything like that. This is
- 9:25basically a callback, so I'll just say
- 9:26null over here, and then the space, so
- 9:29I'll just put two over here. See, you
- 9:31can read all of this description right
- 9:33here in the VS Code. Adds indentation,
- 9:34white space, and line break characters
- 9:36to return the value JSON text. Okay,
- 9:38cool. And after that, we can have a
- 9:41callback function right here. We'll take
- 9:43the error if there's any error, we are
- 9:45going to print that error. Otherwise,
- 9:46we're going to simply going to console
- 9:47log asynchronous write complete. And I
- 9:50think it should have done because oops,
- 9:52it's starting again and again. Why don't
- 9:54we just use uh
- 9:55node index.js right here. So, you can
- 9:57see async write complete. Let's go to
- 9:59the data.json. You can see all of these
- 10:02three objects are right here. Right.
- 10:04Now, let's go on and create our very
- 10:06first server in Node.js. So, to create a
- 10:09web server in Node.js, you have to
- 10:10import something called as an HTTP,
- 10:14which comes from Node.js. And I'll say
- 10:16const server equals http. create
- 10:21server. And this basically takes a
- 10:23callback right here with request and
- 10:27response. And inside of this, we can
- 10:29define our different different
- 10:30endpoints. So, I'll say if request.url.
- 10:34So, this basically this request object
- 10:35provides us a bunch of different things.
- 10:37One of them is URL. So, I'll say if URL,
- 10:39if it's equals to slash, that is just
- 10:41simply localhost or whatever the
- 10:43endpoint of your API is, and I'll say
- 10:45and
- 10:46request.method.
- 10:48So, basically there are four types of
- 10:50method: get, post, put, and delete. Get
- 10:53is for reading, post is for creating
- 10:55something, put is for updating
- 10:57something, and delete is obviously for
- 10:59deleting something. Right? So, this one
- 11:01will be a get request. So, if that is
- 11:03the case, I'll send some response over
- 11:05here. Right? So, I'll say response.write
- 11:09head. So, this sends a response header
- 11:12to the request. I'll say 200. Now, there
- 11:14are a bunch of different different types
- 11:15of request code over here. You can just
- 11:18Google HTTP response codes, and you will
- 11:21land on this you know MDN website. So,
- 11:23for informational responses, hundreds,
- 11:25successful responses from 200 to 299,
- 11:28for client errors, 400, server errors,
- 11:30500. So, we have different different
- 11:32types of responses. And if I click on
- 11:34the successful responses, you'll find
- 11:36each and every code right here. So, I
- 11:38would highly encourage you guys to go
- 11:39through this. We are going to be sending
- 11:41the success code right here, 200. And
- 11:43content type will be text/plain. And
- 11:46then I'll say response.end, "Welcome to
- 11:48Job Tracker API." Right? How about we go
- 11:51on and try to run this? So, I'll just
- 11:52run npm run dev. Okay, our API is
- 11:56started. And actually, we need to serve
- 11:58it in some sort of uh endpoint, right?
- 12:01So, I'll say server.
- 12:03listen. I'll choose the port to be 3000.
- 12:07And here in the callback, I'll just
- 12:09simply say console.log, "Server running
- 12:11on localhost:3000." So, see. It is
- 12:13printing it right here. Let's go to this
- 12:14endpoint. And there we go. We can see,
- 12:16"Welcome to Job Tracker API."
- 12:19Awesome. Let's create another type of
- 12:21endpoint. So, I'll say else if What if
- 12:25uh the endpoint is something like
- 12:26{slash}health? So, request.url equals
- 12:28{slash}health and request.method is
- 12:30equals to get. Then, I'll just say 200
- 12:34code with application/json. And I'll
- 12:36simply send the status to be okay. Let's
- 12:38try to hit this endpoint. So, I'll say
- 12:40health. Press enter. There we go. The
- 12:43status is okay. Awesome. And if it is
- 12:45none of these things, I'll just simply
- 12:47say response.writeHead 404, that is not
- 12:50found. 404 code.
- 12:52And content type will be text/plain. And
- 12:55response will be not found. Let's try to
- 12:58enter some ran- something random over
- 12:59here. And you can see, "Not found."
- 13:01Cool. So, you have successfully created
- 13:03your very first web server or your very
- 13:06first API endpoint. But you can see,
- 13:08this feels a little bit tedious, right?
- 13:11Imagine writing else if else if for I
- 13:14don't know, 50 different API endpoints
- 13:16or even 15 different API endpoints. It
- 13:19will be an absolute nightmare. And that
- 13:21is why the modern apps use something
- 13:23called as Express. Right? So, you can
- 13:26see, raw Node JS is like built from
- 13:28bricks, but Express is made with
- 13:31pre-built walls. It has modules that are
- 13:33ready to use and you can stick them
- 13:35together to create a web server in much
- 13:37more easier way and create your APIs in
- 13:39much faster time. Let me actually show
- 13:41you. We already installed Express,
- 13:42right? So, instead of all of this now,
- 13:46we are going to be importing
- 13:48Express right here. Assign it to
- 13:50Express. I'll say const app equals
- 13:53Express right here. Now, we can simply
- 13:56say app. Whatever the request that we're
- 13:59trying to make, get, post, put, delete,
- 14:01whatever, right? So, I'll just say get
- 14:03and I'll say {slash} and I'll have a
- 14:06callback right here. Again, this will
- 14:08take request and response, but inside of
- 14:11this curly braces, it has handled all of
- 14:14the code and content type stuff and we
- 14:16can simply just send the response. I'll
- 14:17say response .send welcome to job
- 14:19tracker API. And then, if you want to
- 14:21listen on a particular port, I can say
- 14:22app.listen
- 14:24port 3000. And inside of callback, I'm
- 14:27going to write console.log server
- 14:29running on port 3000. Let's see inside
- 14:31of our terminal. Yep, that is fine.
- 14:33Let's go and check the localhost 3000.
- 14:35Yes, awesome. This is working
- 14:37flawlessly. So, earlier we had so much
- 14:40code and now it has been simplified to
- 14:43just a few lines. And again, guys, if
- 14:44you want the link to this complete cheat
- 14:46sheet, let me know in the comments down
- 14:47below. Now, similar to this route that
- 14:50we have created right here, we can
- 14:51create different different types of
- 14:52routes.
- 14:53Like one of the examples that I would
- 14:54like to give you is uh if I just copy
- 14:56and paste this right here. If we want to
- 14:58go to {slash} application and a
- 15:00particular ID over here, right? So, we
- 15:02don't know that ID. So, we're going to
- 15:04be replacing it with this colon ID over
- 15:06here, so that this becomes a dynamic
- 15:09route. Now, simply over here, we can say
- 15:11inside of backticks, actually, fetching
- 15:14application with ID and the particular
- 15:16ID that we're trying to search, right?
- 15:17So, let's try to go to this the {slash}
- 15:19applic-
- 15:21-ations {slash} let's just say ABC over
- 15:24here. And you can see fetching
- 15:25application with ID ABC. Now, you guys
- 15:28may have also seen in our URLs, we have
- 15:31something like this. So, for example,
- 15:32{slash} application and {question mark}
- 15:34status
- 15:36equals, let's say, applied. Right? So,
- 15:39how does this work? How does
- 15:41these search param work? Currently, it
- 15:43will just say cannot get. So, again, I'm
- 15:45going to duplicate this right here, and
- 15:48I'll just remove this to keep it {slash}
- 15:50applications. And inside of it,
- 15:52actually, we get something called as
- 15:53request. {dot} query. And from inside of
- 15:57this, we are going to destructure
- 15:59whatever that we want to get, right? So,
- 16:01status in this case. And let's just
- 16:03console log filtering with filtering by
- 16:06status and whatever the status is.
- 16:08Let's see. If I just refresh this now,
- 16:10you can see filtering by status applied.
- 16:13Awesome. Now, there's something called
- 16:14as a middleware when we use Express.
- 16:17Whenever we make a request inside of our
- 16:20URL, it goes through that particular
- 16:22middleware before providing us with
- 16:24response. And it looks something like
- 16:25this. So, app.use, and we can perform a
- 16:28particular action in between. Let me
- 16:29show you how. So, right here, right
- 16:32after this, actually,
- 16:34I'm going to say app.use
- 16:37express
- 16:39.json. Now, this will allow me to return
- 16:42the middleware that only parses JSON and
- 16:44only looks at the request where the
- 16:47content type matches the JSON type. So,
- 16:49we don't have to check it again and
- 16:51again, right? And let's create another
- 16:53middleware, app.use, and I'll take a
- 16:56callback right here with request,
- 16:58response, and something new called next,
- 17:00so that we can allow it to go to the
- 17:02next step. I'll simply console log
- 17:04request.method right here and
- 17:06request.URL, and I'm going to call this
- 17:09next over here, so that it moves
- 17:11forward.
- 17:12Okay. Let's try to refresh this, and
- 17:15let's go back to our terminal,
- 17:17and you will see inside of our terminal
- 17:18we have the request.method to be get and
- 17:21request.url to be /applications.
- 17:24And keep in mind if you forgot to add
- 17:26this next over here, then your app will
- 17:29be stuck forever in this place and it
- 17:31will completely, you know, be unusable.
- 17:33So, this is the number one beginner
- 17:34mistakes mistake that a lot of people
- 17:37make. Okay. Now, before moving on to
- 17:39creating our complete job tracker API,
- 17:41let's also understand how we can handle
- 17:44errors using middleware. So, I'll just
- 17:47say app.use and this inside of this the
- 17:50callback also takes the error, something
- 17:54like this. So, error, request, response,
- 17:56next.
- 17:57Inside of this, I'll just print whatever
- 17:59the error is over here and we can also
- 18:01say response.status
- 18:03to be with respect to that error we can
- 18:04throw the response, right? So,
- 18:06response.status 500 and something went
- 18:08wrong. Let's actually take this and put
- 18:10it right before app.listen. This is
- 18:12where we, you know, usually put all of
- 18:14these errors. And if I refresh my app
- 18:16now, nothing happens. It's because this
- 18:18will, you know, handle if there's any
- 18:20actual error inside of our app and right
- 18:22now there isn't. All right. Now, finally
- 18:24we are going to be working on our full
- 18:25CRUD API. We're going to be creating all
- 18:27of these different different routes by
- 18:29building this job application tracker
- 18:31API with the following features. So, let
- 18:34me actually show you what are all the
- 18:35different different endpoints going to
- 18:36be. So, for example, if you want to list
- 18:38all of the applications inside of our
- 18:40app, we can just provide it with the
- 18:42following things like applied,
- 18:44interview, offer, rejected, whatever the
- 18:47current status is. You can even sort it
- 18:50using date. I have even added pagination
- 18:53inside of it and I'll show you how you
- 18:55can build pagination with these types of
- 18:56API endpoint. If I click on execute,
- 18:59you'll see that we will get our response
- 19:02just like this. Currently, I've just
- 19:03added one job application in there,
- 19:05that's why. But, we can also create new
- 19:08applications over here in the
- 19:09/applications. You can see this is the
- 19:11type of a schema that you can use right
- 19:13here. So, if I click on try it out and
- 19:15let me just change it to something like
- 19:17meta and click on execute now. Okay, it
- 19:20has been created, but if I go back up,
- 19:23well, let's try to hit this get endpoint
- 19:25again and this time I'll try to let's
- 19:27say add five results even though we just
- 19:29have two in there. So, I click on
- 19:31execute. Yep, there we go. We can see
- 19:33the newly added one over here as well.
- 19:35Let's take this ID and let's make use of
- 19:38this slash application slash ID. So, if
- 19:40I
- 19:41click on try out,
- 19:43I'll just say two over here, execute and
- 19:44we can get that specific job application
- 19:48over here. We also have stats over here.
- 19:51If I click on try it out, you'll notice
- 19:53that this will give us different
- 19:55different stats like up how many have we
- 19:56applied on, how many were reject
- 19:59rejected, interview, etc. Right?
- 20:00Currently, we just have the applied,
- 20:02that's why it's just showing this. We
- 20:04also have other endpoint like update an
- 20:06application, delete an application,
- 20:09right? So, all of these is what we're
- 20:11going to be building next. All right, so
- 20:13up until this point, we were writing all
- 20:15of our code inside of this one index.js
- 20:17file, right? But,
- 20:19in the production apps, we generally
- 20:21write our code in different different
- 20:23routes and controllers files, right? So,
- 20:26first of all, let me just rename this
- 20:27file to app.js and inside of
- 20:28package.json, I'm going to be
- 20:31calling it app.js, right? So, let me
- 20:34show you. See, something like this. We
- 20:35will create the routes folder for
- 20:38defining all of our different different
- 20:40routes and the controllers which will
- 20:42basically contain the core logic of our
- 20:45APIs. So, let's create both of these
- 20:47folders right here. New folder, routes
- 20:50and I'm going to create a new folder for
- 20:52controllers.
- 20:53Okay. Now, inside of this app.js, let's
- 20:56first create our web servers just the
- 20:58way that we learned, right? So, I'll
- 21:00import express first. So, const express
- 21:02equals require express. After that,
- 21:04obviously, we are going to be taking or
- 21:06initializing our app with Express so
- 21:09that we can create our server and also
- 21:11we will add the middleware by saying we
- 21:13should return middleware that only
- 21:14parses JSON and only looks at requests
- 21:17where content type matches this option.
- 21:19And whenever we hit any endpoint, what I
- 21:22want is right here inside of our
- 21:24terminal, we want to see
- 21:26which endpoint we hit. So, I'll add one
- 21:28more middleware over here. Request,
- 21:30response, and next.
- 21:31I'll say console.log request method and
- 21:33request URL, right? And I'm going to say
- 21:35next. Now, as I showed you to create a
- 21:37server, we say app.listen.
- 21:40We're going to be listening on 3000
- 21:42port. And inside of this callback, I'll
- 21:44say job tracker API running on this
- 21:46localhost 3000. Okay, that's fine. For
- 21:49our
- 21:50simple uh slash route, we're not going
- 21:52to be having anything. So, I'll just
- 21:53simply say welcome to the job tracker
- 21:55API. Let's just quickly test it out to
- 21:57see if this is run working. Yep, there
- 22:00we go. Welcome to job tracker API. It is
- 22:02working fine. Now, for our main routes
- 22:05like {slash} application. So, what I'll
- 22:07do I'll
- 22:08uh just I'm going to copy and paste it
- 22:09right here and I'll remove this from
- 22:12over here.
- 22:13So, it'll be {slash} appli-
- 22:15cations. What this will do, it will
- 22:17fetch all of this data from this
- 22:18data.json file. And by the way, for this
- 22:21tutorial, we're not taking any database
- 22:22to keep things simple and so that you
- 22:24guys are able to understand Node and
- 22:25Express, we are going to be writing
- 22:28our data, reading the data, you know,
- 22:30creating, deleting, updating all of them
- 22:32inside of this JSON file. Let me know in
- 22:34the comments down below if you want me
- 22:35to create a much more in-depth Node.js
- 22:37tutorial where we build a complete
- 22:40end-to-end API with database, auth, and
- 22:42all of those things, right? For this
- 22:43tutorial, the scope is mainly to get you
- 22:45started with Node.js. Okay. So, over
- 22:47here, we will define our route
- 22:49basically. Let's call it applications
- 22:50router. And obviously, we will get the
- 22:52error because this does not exist. So,
- 22:54inside of the routes folder over here,
- 22:56I'll create a new file called
- 22:58applications
- 23:00.routes
- 23:02.js. And right here, first of all, I'm
- 23:04going to be importing Express, and then
- 23:06I'll say const router equals Express dot
- 23:10router. So, over here, basically, router
- 23:13will allow us to create the sub routes
- 23:15under a particular route. So, we have
- 23:18{slash} applications, right? So, now, if
- 23:21we say {slash} over here and create some
- 23:23logic, it means it will be {slash}
- 23:25application. If we say {slash} ID, it
- 23:27will be {slash} applications {slash} ID.
- 23:29Let me
- 23:30So, over here, first of all, we are
- 23:32going to be creating
- 23:33the get all applications logic. For
- 23:36that, I'm going to say router dot and
- 23:38we're going to be providing the method,
- 23:39if it's get, post, put, etc., right? So,
- 23:41this will be get. And I'll say {slash}
- 23:44over here. Then, comma, we are going to
- 23:45be adding the logic corresponding to
- 23:48that, right? And in the end, we're going
- 23:49to say module.exports
- 23:52equals router.
- 23:54And then, we can simply go to our app.js
- 23:57and import it
- 23:58right here. Something like this. So,
- 24:00applications router, require, and then
- 24:02the path to that particular file. Now,
- 24:04our app won't give us any errors. Okay,
- 24:06so, apart from that, what else we had?
- 24:09We want to get application counts by
- 24:11status, we want to get single
- 24:13application by the ID. Now, one thing
- 24:16very important to understand right here
- 24:17is the way that you write your get
- 24:20routes matter a lot. So, if you will
- 24:23write this {colon} ID first and this
- 24:26{slash} stats later on, Express will
- 24:28think that this stats is also an ID, and
- 24:31it will, you know, correspond it with
- 24:32this particular route only, because it
- 24:34reads from top to bottom. So, that is
- 24:36why if you have any {colon} ID or
- 24:38something like that, it is
- 24:39important to write it below the {slash}
- 24:42whatever the route is. Let me show you,
- 24:45actually. I'm going to duplicate this
- 24:47over here and here as well. This one
- 24:50will be stats, and this one will be
- 24:52{colon} ID. And obviously, we are going
- 24:54to be writing the logic for each and
- 24:56every one of these. So, let's actually
- 24:58create all of these get APIs over here.
- 25:01And again, as I mentioned, we are going
- 25:02to be manipulating the data inside of
- 25:04it. So, instead of our controllers
- 25:06folder, I'm going to be creating a new
- 25:08file applications.controller.js.
- 25:12And for each route over here, like for
- 25:14example, to get all applications, we are
- 25:16going to be creating different different
- 25:17controllers. Like for example,
- 25:19exports.get
- 25:20all applications.
- 25:22And this will be a function just like
- 25:24this. And how would you import it? So,
- 25:26I'll go right here instead of this. I'll
- 25:29write this. And you can import it
- 25:31something like this.
- 25:33Or you could have also done controller
- 25:36over here and done something like
- 25:37controller.get
- 25:39all applications. I'm going to be doing
- 25:41the previous one where I destructured
- 25:43the controller right here. This is much
- 25:44more cleaner. Now, before writing the
- 25:46logic for each and every one of these
- 25:48controllers, let's do one thing. Let's
- 25:50complete our app.js file. Below this,
- 25:53I'm going to say app.use. And I'm going
- 25:55to check if a route does not exist. User
- 25:57is trying to hit a route that does not
- 25:59exist. I'll say request, response.
- 26:03Below it, I'll just say response.status.
- 26:05And we can provide the code over here as
- 26:07well. So, 404 not found. I'll say dot
- 26:10JSON. And I'll provide the response over
- 26:12here. Success to be false and error
- 26:14route not found. After that, we will
- 26:16also do error handling. So, app.use.
- 26:19And here, as I showed you, we are going
- 26:21to be having error, request, response,
- 26:23next. And inside of this, we can simply
- 26:25just say console error, whatever the
- 26:27error is.
- 26:28And re-
- 26:29response.status 500. That is server
- 26:32error. Dot JSON. Success to be false and
- 26:34error internal server error. Cool.
- 26:37Now, let's go back to our
- 26:38applications.controller.
- 26:40We are going to be reading the data from
- 26:42this data.json, right? And again, as I
- 26:44mentioned, you guys can use a DB if you
- 26:46want over here as well. But for the
- 26:48simplicity of this tutorial, you can
- 26:50follow along and read the data from this
- 26:52file right here. So, let me show you how
- 26:53we can do that. So, obviously, we are
- 26:55going to be using these two modules, fs
- 26:57for reading the files or reading or
- 26:59writing the files, and path for getting
- 27:01the path to that particular file. So,
- 27:03I'll say const data, oops, data file, or
- 27:07you can also call it DB or whatever,
- 27:08right? path.join,
- 27:11and I'll say current path, so underscore
- 27:13underscore dirname, comma, and I'll say
- 27:16dot dot slash. We want to go to this
- 27:19file, right? data. json to dot dot
- 27:20slash, that is one folder back,
- 27:23data.json.
- 27:24Okay. Now, I'm going to be creating a
- 27:26couple of helper functions over here.
- 27:28One is for reading the data, and one is
- 27:30for writing the data. So,
- 27:32function read data first. I'll say const
- 27:35raw equals fs. I'll say read
- 27:40file. We are going to be making the
- 27:41asynchronous call to reading the file,
- 27:43right? I'll say data file, comma,
- 27:47UTF
- 27:488 type. And then, simply, we are going
- 27:50to return the JSON.parse.
- 27:53We're going to be parsing this data, and
- 27:55we're going to be taking out the
- 27:56applications
- 27:58from inside of it. So, let me show you
- 27:59actually
- 28:00this data.json file. We have this
- 28:03applications over here, right? So, this
- 28:05is what we want as a response to our
- 28:07front end, to send to our front end.
- 28:09Now, we are going to say write data. So,
- 28:11we will get the applications data that
- 28:13we're supposed to write inside of this
- 28:15data.json file. So, I'll say fs.write
- 28:19file synchronously, or you can also use
- 28:22asynchronously, as well.
- 28:24We can use that. And I'll say data
- 28:26file, JSON.stringify.
- 28:29Here, I'll provide the applications that
- 28:31we are sending. Next parameter will be
- 28:34null. We don't want to transform it, and
- 28:36I'll say
- 28:37two for indentation and white spaces.
- 28:40Okay, cool. So, these are all the helper
- 28:42functions that we are going to be
- 28:43needing. Let's start
- 28:45working on this controller now. So,
- 28:47inside of this, first of all, I'm going
- 28:48to say request.query.
- 28:51So, if you remember, when we are getting
- 28:54our applications, we have multiple
- 28:55different things that we are sorting it
- 28:57by, like applied, what page we are on,
- 29:00how many results we need to send, and if
- 29:02we need to sort it or not. So, we are
- 29:04going to be taking out all of these
- 29:06things from our request. So, I'll say
- 29:08const, and here I'll take out the
- 29:10status, sort,
- 29:12page, and the limit. Okay?
- 29:15Below this, we are going to be using
- 29:17this read data over here and read the
- 29:19data of our file. So, I'll say const
- 29:20result equals read data. Then, we're
- 29:22going to be writing logic for each one
- 29:24of these, right? So, first of all, for
- 29:25the status, I'm going to check if status
- 29:28has been provided by the user.
- 29:30I'll say result.filter. We are taking
- 29:32all of our applications, and I'm saying
- 29:34applications.status
- 29:35is equals to this particular status,
- 29:37only then return it inside of this
- 29:39results right here. Okay? Then, I'm
- 29:41going to check if sort is equals to
- 29:45date. That means we want to sort it with
- 29:47respect to the date, right? Then,
- 29:48simply, we are going to be using this
- 29:50dot sort right here. So, I'll say
- 29:51result.slice and dot sort. We're going
- 29:54to be taking A and B over here. That is
- 29:56the first and the second. So, if we are
- 29:58going to say if A.applied date is more
- 30:00than B.applied date, then it will be
- 30:02one, otherwise minus one. So, sort is in
- 30:04itself a complex function. You guys can,
- 30:06uh, you know, search Roadside Coder
- 30:08sort, and you will find my explanation
- 30:10on YouTube. So, basically, we're sorting
- 30:11it in the descending order if it's one.
- 30:14If it's minus one, it is ascending order
- 30:15if I am not wrong. After this, if the
- 30:18page and the limit is provided, we're
- 30:20going to take both of them in this
- 30:22variable over here, right? We're going
- 30:24to format it into number.
- 30:26And after that, I'll say const start
- 30:29equals page num minus one into whatever
- 30:33the limit is. So, we're going to
- 30:36basically start it with respect to
- 30:37whatever page that we are in. If we are
- 30:39on one, we're going to be going from
- 30:40zero to whatever the limit is. Like, for
- 30:43example, if it's 10, so 1 to 10. If it's
- 30:46page number is two, so we will start
- 30:47from 11 to 20. Something like that,
- 30:49right? So, we will say result.slice
- 30:52start and go until whatever the limit
- 30:54is. Start plus limit num. And then in
- 30:57the end, we need to send the response,
- 30:58right? So, we need to write again and
- 31:00again response.status, whatever, right?
- 31:02So, the better way will be to create a
- 31:04helper function for this. So, for
- 31:06success response, I'm going to be
- 31:08creating send
- 31:09success with response, status, and data
- 31:14inside of it. I'll say response.status,
- 31:16whatever the status code is. Oops, like
- 31:19this. I'll say dot json. Inside of this,
- 31:22I'll say
- 31:23success to be true and the data that we
- 31:26want to send. Similarly, if you want to
- 31:28send the error, we're going to be having
- 31:30a function for send error as well. So,
- 31:31response, status, and message. I'm going
- 31:33to say response.status to be status and
- 31:36dot json.
- 31:37Success to be false and error to be
- 31:39message. Now, for this controller, I'm
- 31:41simply going to say send success with
- 31:43the response, code 200, and our result.
- 31:46Also, by the way, I realized this has to
- 31:48be app.use,
- 31:50not app.get. Now, up until this point,
- 31:52we were using
- 31:54a browser to hit the endpoints, right?
- 31:56So, slash up Oh, what is this? Internal
- 31:59server error. So, okay. So, actually,
- 32:02right here in our controllers, instead
- 32:04of read file, for now, we are going to
- 32:06be reading like using read file sync
- 32:08because we are using this static file
- 32:10over here, right? We're not making calls
- 32:11to any database. And for write file as
- 32:14well, write file sync. Now, if we use
- 32:16this, yes, we can see the data right
- 32:18here. So, as I was saying,
- 32:19we were using browser up until this
- 32:22point to check our API responses, but
- 32:24this is not the good practice. In the
- 32:26production apps or in the companies,
- 32:28what people generally do is they would
- 32:30use something like Thunder Client.
- 32:32Right, you can go to the extensions tab
- 32:34and search Thunder Client and install
- 32:36it. So, if you click on new request and
- 32:38let's paste endpoint right here and
- 32:41click on send. You will get the response
- 32:44right here and it is much more easier to
- 32:45test it out. So, if I let's say add
- 32:49status to be Okay, over here we can add
- 32:52applied, right? And we can say page
- 32:56to be one
- 32:57and limit to be I don't know, two. So,
- 33:00it will just It should give us two
- 33:02results now. So, if I say Yes, after
- 33:04sending it, we are getting two results.
- 33:06Awesome. So, it is much more easier to
- 33:08test out our APIs right here. We can
- 33:10also change it to post, put, delete,
- 33:12etc. And this is honestly the industry
- 33:14standard way. We can also use something
- 33:16like Postman as well, but I prefer this.
- 33:18This is right inside of our VS Code, so
- 33:21it's much better.
- 33:22So, I'll go to our applications.route.js
- 33:25and let's create our second endpoint for
- 33:28getting the single application by ID.
- 33:30So, over here in the
- 33:31applications.controller,
- 33:33I'll just
- 33:34minimize this one and here let me just
- 33:37copy this up actually.
- 33:39Let's export start get applications
- 33:42or get application by ID. First of all,
- 33:44obviously this is going to be {slash}
- 33:46application {slash} some number, right?
- 33:48So, we would need to take out that
- 33:50particular number that we're trying to
- 33:51find. Inside of it, I'm going to say
- 33:53const ID equals number and
- 33:55request.params.
- 33:57So, the params is what we need. .id. Let
- 34:00me actually take this and put it right
- 34:03here.
- 34:04And import it as well. Something like
- 34:07this. Now, right after this, we are
- 34:09going to be finding if that application
- 34:11even exists inside of our database. So,
- 34:12I'll say const application equals read
- 34:15data.find
- 34:17like each and every application, I'll
- 34:19say application
- 34:20.id if it's equals to this ID that we
- 34:24have written right here. Right? If it
- 34:26does not exist, we are going to return
- 34:28the send error helper function that we
- 34:30had created right here.
- 34:32Response, 404 application not found.
- 34:35After this, we are going to be sending
- 34:37the success. Okay, this should be much
- 34:39more straightforward. Let's go to this
- 34:41under ID. I'll create a new request.
- 34:42I'll say localhost:3000
- 34:45applications and slash uh let's say two
- 34:48over here, right? And click on send.
- 34:51There we go. We are getting it right
- 34:53here. Awesome. All right. Now next,
- 34:55let's create this stats route. And
- 34:58actually, you know what? I already told
- 34:59you how you can create different
- 35:00different get routes, right? So, I want
- 35:03you guys to work on this get stats
- 35:06route. Let me just import it right here.
- 35:08Something like this. And it's going to
- 35:10be very simple, actually. We are going
- 35:12to be, you know, filtering them with
- 35:14respect to the
- 35:15applied, interview, etc., etc. And you
- 35:18know, you can give the output like this,
- 35:22right? Like applied two, interview one,
- 35:24etc. So, I guess you can use something
- 35:26like reduce over here. I guess that's
- 35:28enough hint for this one. Let's go on
- 35:30and start working on our post route,
- 35:33that is creating our applications. So,
- 35:35for that, let me just add the comment.
- 35:37And actually, let me just add more
- 35:38comments over here, like for updating an
- 35:41application, deleting an application.
- 35:44So, I'll say router.post.
- 35:47This will be a slash route, comma I'm
- 35:49going to be naming it create
- 35:50application. So, I'll go to
- 35:51applications.controller right here.
- 35:54Right below this, I'll say
- 35:55exports.create application. And let's
- 35:58just
- 35:59paste it right here. Import it. Let me
- 36:01also create the controllers for the
- 36:04update application and the delete
- 36:06application. And let me import these as
- 36:09well right here. So, for update, we are
- 36:11going to be saying router.put,
- 36:14and it will be slash application slash
- 36:16particular ID over here. And we're going
- 36:17to be taking
- 36:19the update application. Let's import it.
- 36:21Similar to this, for deleting it as
- 36:23well, we are going to be providing the
- 36:24ID and we can delete it, right? So,
- 36:26let's import that as well. Cool. Let's
- 36:28first start working on our create
- 36:30application, the post request.
- 36:32And by the way, if you noticed, we have
- 36:34used dot delete over here for the delete
- 36:35request.
- 36:37Okay. So, obviously, to create an
- 36:38application, we would need to take out
- 36:40like company, role, and status from the
- 36:42request's body that user will send to
- 36:45our API. So, I'll say
- 36:47const company, role, and status. We're
- 36:49going to be destructuring it from our
- 36:50request.body. After this, I'll check if
- 36:53company or role does not exist, I'll
- 36:56return the error. So, I'll say return
- 36:57send error again, the helper function
- 36:59that we created, the response 400 error,
- 37:02company and role are required.
- 37:04Okay. After this, let's get all of the
- 37:06applications using this read data
- 37:08function.
- 37:09And then, with respect to the last ID of
- 37:11the application that we have created, we
- 37:13are going to be creating the next ID.
- 37:15So, I'll say const next ID equals
- 37:17applications.length.
- 37:19If length if it's more than Oops,
- 37:21length. If it's more than zero, I'll say
- 37:24Math.max,
- 37:27and I'll take all of the applications,
- 37:29and I'll say dot map for each and every
- 37:31application ID, and I'll say plus one to
- 37:33the last ID. Otherwise, we're just going
- 37:35to call it one. So, that means it is the
- 37:37first application. We don't have any
- 37:39applications as of now. Whichever will
- 37:41be the max, we will get it from over
- 37:42here. And obviously, the last one will
- 37:44be the max one. So, we'll take that, and
- 37:46we will say plus one to it. After this,
- 37:48I'll take the current date. So, I'll say
- 37:50apply date equals new date. To ISO
- 37:52string. Dot split from T. I'm not going
- 37:55much in-depth in this. This is like
- 37:56basic JavaScript concepts. And then
- 37:58finally, if we are going to be creating
- 37:59a new application, I'll create a new
- 38:02variable over here for new application.
- 38:03I'll say ID to be this next ID. Company,
- 38:06role, status can be other status, the
- 38:08whatever user has sent, or we can say
- 38:10applied by default. And also, the
- 38:12applied date. Right? Finally, I'll say
- 38:14applications.
- 38:16push. So, what whatever the applications
- 38:19that we read. Right? So, new
- 38:20application, and I'll say write data
- 38:23over here. Now, this will be an
- 38:24asynchronous operation. I'll say
- 38:26application or applications, actually.
- 38:29After this, I'll just say send success
- 38:32to response 201 status and new
- 38:36application. All right, how about we go
- 38:38on and try this out? So, I'll just go to
- 38:40the Thunder ID. So, I'll have new
- 38:42request over here. Actually, uh let me
- 38:44just go right here and create a separate
- 38:46new request.
- 38:48I'll say localhost
- 38:50applications and maybe this
- 38:52applications, yeah. And I'll say post
- 38:54over here. And in the body, we can
- 38:56provide the content. Like I'll say
- 38:58company
- 39:00to be, let's say, Nvidia, role
- 39:03to be SWE E
- 39:06and status can be interview. Let's click
- 39:10on send. What's the error? Internal
- 39:11server error. I guess we need to put
- 39:14this in double quotes, something like
- 39:16this, and click on send. Yes, now it has
- 39:18been created. Let's go on and check
- 39:19inside of data.json. There we go. We
- 39:22have created a new entry inside of our
- 39:24file DB.
- 39:25Awesome. Let's go back and start working
- 39:28on the update application as well. And
- 39:30again, I would highly encourage you guys
- 39:32to work on this yourself first and then
- 39:34see my solution. So, this will be pretty
- 39:36straightforward. We will take out the
- 39:38param, the ID param. We will read all of
- 39:41the applications and then find that
- 39:43particular application with this ID.
- 39:45Straightforward again. And I'm going to
- 39:47check if the application does not exist,
- 39:49I'm going to send the error application
- 39:51not found. Otherwise, we will get the
- 39:53updated data from the user. So, user
- 39:56will send us company, role, and status,
- 39:57whatever they want to update. And then
- 39:59I'll check if company is not equals to
- 40:02undefined, then we will, you know,
- 40:03update the company in that particular
- 40:04application. Same for role, same for a
- 40:07status. And after that, I'm going to
- 40:09write the data to our applications array
- 40:13right here. And notice how I'm directly
- 40:14writing it with this without uh
- 40:16reassigning it. because since we are
- 40:19making the change to application
- 40:20directly, it will be making the change
- 40:22to this as well. This is how, you know,
- 40:23JavaScript object works.
- 40:25by reference. And after this, I'll say
- 40:28send success response 200 application.
- 40:32Okay, let's try this one out as well.
- 40:33New request. How about we go on and
- 40:36update? Let's check what we need to
- 40:37update. Let's just update this one only.
- 40:39So, I'll take all of these three things.
- 40:43And here I'm going to create a new
- 40:44request for localhost. Let's say
- 40:47applications will be four, and this will
- 40:50be a put request. Right? And the body,
- 40:53I'll actually copy it up from post.
- 40:56Where is it? There it is. I'll just copy
- 40:58it up. Paste it right here. Instead of
- 40:59Nvidia, how about we say open AI. Click
- 41:03on send.
- 41:04Looks like it has been updated. Let's go
- 41:06on and check. Let's adjust this one.
- 41:07Yes.
- 41:08It has been replaced by awesome.
- 41:10Finally, let's go on and build our
- 41:12delete application as well. So, inside
- 41:14of this, to create a delete route in
- 41:17Node.js,
- 41:18we said router.delete, whatever the
- 41:21endpoint is, and the delete application,
- 41:23whatever the controller is, right? And
- 41:24let's go on and write the logic inside
- 41:26of it. Again, similar to previously, we
- 41:28are going to be taking
- 41:30the application. So, I'll We're going to
- 41:31be hitting the ID, right? So, I'll say
- 41:33const ID. I'll take it from the params.
- 41:35I'll take all of the final application
- 41:37and find that particular application.
- 41:39Right? But, then in this case, it won't
- 41:40be find. It will be actually be find
- 41:43index because we're going to be deleting
- 41:45it, that particular index.
- 41:47After this, I'll say if index is equals
- 41:51to minus one, that is it does not exist,
- 41:53then I'll return the send error 404
- 41:56application not found.
- 41:57After this, we're going to say
- 41:58applications.splice. So, splice will
- 42:01help us delete something from a
- 42:02particular index. So, I'm saying from
- 42:05this index, delete one element. After
- 42:07this, say write data with the
- 42:08application, and I'll say
- 42:11response.status 204. And
- 42:13you know, since we don't have any
- 42:14content, so we will skip the helpers and
- 42:16just end the response. All right, let's
- 42:18go and try deleting it as well. I'll
- 42:20click on new request. I'll just go for
- 42:22the same {slash} four.
- 42:24And I'll say delete. Click on send. Oh.
- 42:28Something's wrong. Let's check. It's
- 42:29saying index is not defined. Let's see.
- 42:32Right here. Oh, my bad.
- 42:34I should have
- 42:35said index over here. Let's try this
- 42:37again. And yep, no content. Let's go
- 42:40inside of our data.json and yes, it has
- 42:42been removed. Awesome.
- 42:44And with this, you created your very
- 42:46first CRUD API. Congratulations. Now
- 42:49again, if you want me to create another
- 42:51video where I create authentication, you
- 42:53know, add a database and all of these
- 42:55things and even use TypeScript in this,
- 42:57let me know in the comments down below
- 42:58and I will create complete Node.js
- 43:01course end-to-end with a
- 43:02production-grade application. And if
- 43:04you're preparing for interviews, check
- 43:06the link in the description down below
- 43:07for my complete interview preparation
- 43:09course. I have covered a lot of
- 43:10important JavaScript topics. And if
- 43:12you're a front-end developer, I have
- 43:13covered React JS, system design, and
- 43:15much more. And you can use this code
- 43:16right here to get the maximum discount.
About this transcript
This page contains the full transcript of Learn Node JS in 40 Minutes (Crash Course) - Express, CRUD APIs, etc by RoadsideCoder, generated from the public captions YouTube serves with the video. The transcript has 8,137 words across 1,231 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.