Search code examples
hostinggithub-pagesmern

Can we host MERN stack application (with backend) by using GITHUB pages?


Can we host a web application developed using MERN stack by creating repo on GitHub? for an example, we can create a repo like "app1.github.io" and host it using GitHub pages.

So, can we also host the backend using GitHub pages?

Normally, we can host the front end (HTML, CSS, JS) using GitHub. I want to know about hosting the backend using the GitHub repository.


Solution

  • Hosting a MERN stack application is an exciting project. GitHub Pages is fantastic for your front-end (HTML, CSS, JS) but not ideal for the back end. Let me explain how you can handle each part:

    Front End (React): Absolutely, GitHub Pages can indeed host the front end of your MERN application. You can create a gh-pages branch or configure it to publish directly from your master or main branch. This is where you'd place your HTML, CSS, JavaScript, and React components.

    Back End (Node.js with Express.js): GitHub Pages is not suitable for hosting server-side code, including your Node.js back end. To host the back end, you'll need to look into other hosting platforms like Heroku, AWS, Azure, or similar services that support Node.js hosting. These platforms allow you to run your Node.js server and Express.js application.

    Database(MongoDB): MongoDB is usually hosted on a separate platform, such as MongoDB Atlas, not on GitHub Pages. MongoDB Atlas provides cloud-based database hosting, which can be accessed by your Node.js back end running on a separate hosting service.

    GitHub Pages is a great choice for hosting the front end of your MERN application. However, to host the back end and database, you'll need to explore other hosting options. Combining GitHub Pages with a suitable back-end hosting platform is a common practice for deploying MERN applications.