Deploying a backend on Vercel (APIs and Functions)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Let's talk about deploying your backend  to Vercel. So, Vercel is a frontend cloud,   which means that we integrate with all  of the popular front end frameworks like   Next.js, Nuxt, or SvelteKit. But that doesn't  mean that we don't support running backend   code. Some of these frontend frameworks  work across the client and the server,   so you're able to have API routes or  you're able to server-render pages. But when we talk about backends,  or traditional backends, usually   we think of something that's maybe just an API  or something that's talking to a database. And   you can also run those workloads on Vercel.  So, let's take a look. We have a handful of   templates that you can get started from. The  one I'm going to show today is just a simple   Node.js-based function for your backend. We  also have a template for Fastify and some   other backend tools. You can also use something  like Express if you wanted to, but in general,   you're thinking about the way you write your  backend just a little bit differently on Vercel. And I'm going to show exactly what this looks  like. So, I'm going to hit 'Deploy' from here,   and inside of my Git repository,  which we've already connected to,   it's going to create this new repository  here: nodejs-serverless-function-express.   We're going to make this private.  It's going to deploy to my account.   And what this is going to do is make a  new API endpoint for my application. So,   it's going to download this code, it's going  to kick off this build, and then upload that   new API endpoint to a unique URL that I'm going  to get and be able to access over the internet. Now, this is using Node.js, so I can use all  the latest Node.js features. I can talk to my   database, I can connect to external services,  I can run some potentially long jobs, up to 5   minutes on Pro. I can stream something back from  my AI provider. All of that is possible here. So now, if I click out into my new URL and  I go to /hello, we see our brand new Node.js   function. Now, this is just a backend  API. We could talk to our database here,   we can return back some JSON, some XML, some text  files. We can really do whatever we want here. Now, typically with a lot of these backend  JavaScript frameworks like Express, for example,   you can define a bunch of different routes  in your application in this one file. So,   /api or /api/some-parameterized-slug. I  think Fastify is, you know, kind of also   similar like this. You can absolutely still  use some of these backend frameworks in this   way by essentially rewriting request from this  incoming route to this file that we've created   here inside of our API folder, which is part of  that example that we cloned. But you can also   do it in a way where you have different files  for each different API. So, I have /api/hello,   I have /api/user. You can just drop those  files in a folder, and they'll work with   Vercel whether you want to use a framework  or you want to do something separately. And once you've got that bit of backend logic  that you can use to make a REST API or really   do anything on your backend, you could pull from  a blob store and get back some images that are   stored in one of your stores, for example.  Here, I've got an image here. You could read   from Edge Config, where you can put your critical  redirects for your application, or other kind of   structured JSON data. Or you could even go  look at all the logs for your application. So here, I have all of the requests  that I've made to this /hello. So,   I see this 200, and I see some 304s here,  and I can see the exact request that I made,   the runtime, the location, everything  that happened inside of here. So,   you can get pretty detailed with the  metrics that you want to here as well. If you do want to explore other frameworks that  might have some backend functionality built in,   on our templates page, we have a bunch of  different frameworks listed here. You can   even deploy Python functions to Vercel as  well, too. So maybe you want to use Flask   or Django or some of these other things.  We have a whole bunch of examples here. So, in general, Vercel tries to make it  as easy as possible for you to take code,   whether it's functions that you've  written or your frontend framework,   and get it online as quickly as possible. All right, so that's how you can build your  backend on Vercel by writing API functions   or using some frameworks that allow you to  integrate with your backend. If you want   to see more videos going further in-depth into  writing standalone APIs or backends on Vercel,   let me know, and I can make  more content here. Peace!
Info
Channel: Vercel
Views: 30,678
Rating: undefined out of 5
Keywords:
Id: yLMODEUPJdU
Channel Id: undefined
Length: 4min 14sec (254 seconds)
Published: Tue Jan 23 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.