In this guide, we will walk through setting up a MERN (MongoDB, Express.js, React.js, Node.js) application that includes authentication with email verification, while leveraging Docker for both development and production environments. Think of this as building a high-tech security gate (our authentication) for a cutting-edge Playground (our MERN application) where only verified users can enter. Let’s dive into it!
Getting Started with Docker
Before we move forward, ensure you have Docker installed on your machine. If you haven’t installed it yet, you can follow the instructions here: Get Docker.
Docker helps us deploy our app in containers, making our development process smoother and more efficient. Just like renting an apartment in a well-managed complex, Docker isolates our application effectively.
Setting Up Environment Variables
To configure our application, we need to set some environment variables in the server.dev.env file. You’ll want to rename server.example.env to server.dev.env and include the following variables:
- SENDGRID_API_KEY: Required for sending verification emails. Get your key from SendGrid.
- SESSION_KEY: A strong secret for session management. Generate a unique key: Generate Pre-Shared Key.
- SENDING_EMAIL: The email address used for sending confirmation emails to users.
Running the Application in Development Mode
To get started during the development phase, run the following command in the root directory:
docker compose up --build
This will start both the frontend and backend with hot reloading, enabling you to see changes in real-time—like having a live feedback loop at your amusement park.
Deploying in Production
Once everything works in development, it’s time to set up for production. You will need to create server.prod.env and client.prod.env files.
Execute the following command in your root directory for deployment:
docker compose -f docker-compose.prod.yml --env-file client.prod.env up --build
This command utilizes an Nginx server to serve static files for the frontend. Think of Nginx as the efficient concierge at our high-tech playground, directing users exactly where to go.
Key Features of the Boilerplate
Our boilerplate includes several advanced features:
- Email verification (Token Based) with options to resend or reset.
- Login functionality with a ‘forgot password’ feature.
- Docker setup for both development and production environments.
- MongoDB, Express, React-Redux, Node.js, and TypeScript integration.
- Passport.js for local authentication.
- Use of the SendGrid API for handling email functionalities.
Troubleshooting
If you encounter issues, here are some troubleshooting tips:
- If you added a dependency but Docker can’t find it, consider installing the dependency directly in the container or resetting the volume. You can find more on this topic here.
- Ensure that you’ve registered for SendGrid and configured your API key correctly, as the application won’t function without it.
For further assistance, please feel free to reach out to the community or connect with experts. For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Final Thoughts
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.
With this guide, you should have a solid foundation for implementing MERN authentication with email verification in Docker. Happy coding!

