Is it possible to put express.js api inside my next.js project (not separately)
Answered
Ghost ant posted this in #help-forum
Ghost antOP
I'm building a fullstack project using Next.js (app directory) for frontend and express.js for my custom api. Is is possible to have express api inside something like api folder in Next.js project instead of keeping it in a separate project (splitting project into frontend and api)? I'd also like to deploy it to Vercel as a single project later on. If it's possible do I also have to configure some settings for it to work?
For more context I'm working on a blog app and want to handle auth and CRUD operations in express.js as opposed to built-in next backend api.
Thank you in advance.
For more context I'm working on a blog app and want to handle auth and CRUD operations in express.js as opposed to built-in next backend api.
Thank you in advance.
20 Replies
Ghost antOP
bump
Ghost antOP
bump
I'm pretty sure you can't
Answer
Because Vercel is all serverless
I had to create a seperate repo with my express server
However I would just opt for using Next Backend
It's much easier than Express, and will work on Vercel
@Jesse It's much easier than Express, and will work on Vercel
Ghost antOP
I can't do that for now, I kinda feel like nextauth and serverless functions are harder for me to understand than express
I don't know, maybe you can advise something
I may actually create it separately and then redo the whole project with a different approach, all in next one
Next backend is really easy to understand and is much easier than express trust me, you don’t even have to use next auth if you don’t want to. If you use express as I said you’re going to have to create a separate repo and host it in a different URL which means you’re going to have to introduce a bunch of CORS stuff and really it’s much easier to just use Next backend
I can give you the basics of using Next Backend if you want
@Jesse Next backend is really easy to understand and is much easier than express trust me, you don’t even have to use next auth if you don’t want to. If you use express as I said you’re going to have to create a separate repo and host it in a different URL which means you’re going to have to introduce a bunch of CORS stuff and really it’s much easier to just use Next backend
Ghost antOP
I don't think cors is that complicated, just configure some headers and whitelist of urls
@Jesse I can give you the basics of using Next Backend if you want
Ghost antOP
no, but thank you for the offer, I'll make the next native backend version of the project as soon as I finish the one with express
Yeah it's just annoying to have your server and client hosted on different URLs
might want to mark something as answer if you're done
@Jesse Yeah it's just annoying to have your server and client hosted on different URLs
Ghost antOP
indeed but I guess that's what they do for big scale projects where you have website, mobile app and maybe even more
@Jesse might want to mark something as answer if you're done
Ghost antOP
oh, right