0

Hi I'm new to Nextjs and Netlify. I am currently working on a Next.js project that is hosted on Netlify and wanted to learn best practices.

My questions are:

  1. What is the difference between Netlify Functions and Next.js API routes?
  2. When would I use one over the other?
Jeff Wong
  • 11
  • 1
  • 1
    Your Next.js project sits in a server that returns HTML and other assets, like Javascript files, to render your site. Your "API routes" are regular endpoints in this same server that can return data other than HTML pages. Netlify Functions are "serverless", they run on a server, but that's abstracted away from you, so you can quickly setup endpoints to expose some functionality. They are pretty different, and it's a bit hard to understand why are you mixing them up together. It would be helpful to know if you give more detail about what's confusing about them. – Eduardo Thales Jul 15 '22 at 18:53
  • Thank you for the response! I was confused about why the next.js docs refer to Next.js API routes as "Node.js serverless function" in [link](https://nextjs.org/learn/basics/api-routes). – Jeff Wong Jul 15 '22 at 21:12
  • That's because they're serverless functions, just like Netlify functions. If you're using a Next.js app then I'd recommend you use Next.js API routes. – juliomalves Jul 16 '22 at 13:05
  • Thank you, juliomalves that clarifies a lot! – Jeff Wong Jul 17 '22 at 19:09

0 Answers0