How to Create a New MERN Stack App with the Boilerplate

Feb 7, 2024 | Programming

Welcome to the wonderful world of MERN (MongoDB, Express.js, React, Node.js) development! If you’re a beginner looking to dive into full stack development without the hassle, this minimalist boilerplate repo is your perfect starting point. In this blog, we’ll guide you step-by-step to create, configure, and deploy your own MERN stack app effortlessly.

Why Choose This Boilerplate?

This boilerplate is designed specifically for beginners. It provides everything you need to get started with MERN stack development:

  • Sample CRUD API for testing
  • React app scaffolded with Create React App
  • NPM scripts to streamline development
  • Sample Mongoose connection for MongoDB integration
  • Configurations for deploying on Heroku

Getting Started

To utilize this boilerplate, follow these steps:

1. Set Up Your Environment

First, make sure you have the necessary dependencies installed:

  • Node.js
  • Yarn package manager
  • Heroku CLI

2. Create an .env File

To enable APIs to function during development, you’ll need an .env file. Place it in the root of your project and add your MONGODB_URI like so:

MONGODB_URI=your_mongodb_connection_string

3. Available Scripts

Here’s a breakdown of scripts you can run:

  • yarn start: Launches the server in production mode. Access the sample CRUD API at http://localhost:5000/api/v1/get.
  • yarn run dev: Runs the server in development mode with auto-restart on file changes.
  • yarn run client: Starts the React app in development mode. It reloads with edits and displays lint errors.
  • yarn run mern: Simultaneously runs both the server and client. You can access the API and React app on their respective ports.

4. Deployment Steps on Heroku

Ready to take your app live? Follow these deployment steps:

  1. Check if you have Heroku installed: heroku --version. If not, install it here.
  2. Create a Heroku account if you don’t have one yet.
  3. Open the terminal in your project’s root directory and ensure that a git repository exists (remove .git directory from the client folder if necessary).
  4. Review and update the engine in the root package.json if you want a different node or yarn version.
  5. Log in to your Heroku account using heroku login.
  6. Create a new app with a unique name using: heroku create your_unique_app_name.
  7. In your Heroku dashboard, navigate to your app’s settings and add any necessary Heroku variables such as MONGODB_URI.
  8. Deploy your app with: git push heroku master.

Troubleshooting

If you run into issues, consider the following:

  • Double-check your MONGODB_URI in the .env file.
  • Ensure your Heroku CLI installation is current.
  • Confirm that your Heroku app settings are correct, especially the config vars.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Conclusion

Setting up a MERN stack application has never been this straightforward! This boilerplate ensures that even beginners can hit the ground running. Follow the steps outlined above, and you’ll be well on your way to mastering the MERN stack.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox