If you’re diving into the world of web development, particularly using the MERN stack (MongoDB, Express.js, React, and Node.js), this guide will help you set up a comprehensive boilerplate. This setup not only skips the tedious parts of configuration but gets you straight into coding your app. Let’s break down the setup process!
Demo Highlights
Curious about what this MERN boilerplate can do? Check out the live demo hosted here: mern-boilerplate.arm1.nemanjamitic.com.
Getting Started with Deployment
In the ever-evolving landscape of cloud services, you may have noticed Heroku’s shift in their pricing model. Fear not! This boilerplate includes an updated deployment process using Docker for production on any Linux VPS.
- Check out the original mern-docker-prod repository for Docker instructions.
- Explore the Traefik part of the deployment using traefik-proxy.
- See the Traefik proxy applications set up for the boilerplate at traefik-proxy apps.
Key Features of the MERN Boilerplate
This boilerplate is packed with useful features:
- Server: Implements user and message models with a one-to-many relationship, providing full CRUD REST API operations.
- Authentication: Utilizes Passport with local authentication, as well as oauth strategies for Facebook and Google.
- NodeJS Server: Runs NodeJS with Babel for new JavaScript syntax.
- Validation: Uses Joi for server-side input validation.
- React Client: Built with functional components and Hooks for an engaging user experience.
- Redux: Manages app state effectively with the help of Thunk.
Installation Steps
Ready to set this up on your local machine? Follow these steps:
- Clone the repository:
- Create your
.env
file: - Install Server Dependencies:
- Run the Server:
- Set up the Client:
$ git clone https://github.com/nemanjam/mern-boilerplate.git
$ cd mern-boilerplate
Rename .env.example
to .env
& fill in the necessary configurations like database connections, OAuth tokens, etc.
$ cd server
$ npm install
$ npm run server
$ cd client
$ npm install
$ npm start
Understanding the Server Code
Think of this code as setting up a restaurant. You have the kitchen (Node.js/Express) where food is prepared (data processing) and the dining area (React) where customers (users) come to enjoy the meals (interact with your app). Just like a good menu helps customers choose their meals, good API endpoints allow users to interact with your data smoothly.
Troubleshooting Tips
Although this boilerplate is designed for a seamless setup, you might encounter a few bumps along the way. Here are some common issues and solutions:
- Server Not Running: Ensure you’ve run
npm run server
in the server directory and check the console for error messages. - Database Connection Issues: Make sure your MongoDB URI in the
.env
file is correct and your MongoDB instance is running. - OAuth Failures: Double-check your Google and Facebook OAuth settings; make sure the URLs match those provided in your
.env
.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
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.