deploymentreact-fullstack

Next.js Express.js and MySql app deployment


Since this is the first private project that I have done in Next.js I am wondering how do I host it with backend and database.

All tutorials are about next.js alone, I am not sure what should I use in case to be able to publish full stack app.

Do I need something in main folder to be able to publish the web site? Since I need to change next.js not to run on localhost.

I was thinking about using a2 hosting with cpanel. Also I can also use heroku and register my own domain, but how do I add backend and database

File structure


Solution

  • If you would like to have a backend, NextJs comes with an /api endpoint where you can initialize your server side backend section. but If you would like to have a seperate backend It would be better to initiate a seperate backend api and call it through the frontend. NextJs comes with api folder where you can define different routes for your different endpoints. Regarding file uploads The mentioned NPM Package Will not work Because It's Designed to work with ExpressJs. You can Implement file Upload by Sending Request from FrontEnd as a FormData object.in the backend the automatic bodyParser to false by defining an object as below

    export const config: PageConfig = {
        api: {
            bodyParser: false,
        },
    };
    

    you can use a library like formidable to process the incoming Request. Follow this Guide for more information.