UNPKG

create-mern-backend

Version:

CLI to scaffold MERN backend folder structure with .env and server.js

125 lines (86 loc) 2.65 kB
# create-mern-backend 🛠️ [![npm version](https://img.shields.io/npm/v/create-mern-backend.svg?style=flat-square)](https://www.npmjs.com/package/create-mern-backend) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)](https://opensource.org/licenses/MIT) > A zero-config CLI tool to scaffold production-ready MERN stack backend applications with best practices. --- ## 🚀 Features - **Instant setup** Spin up a MERN backend project in seconds - 📁 **Modular architecture** Clean and scalable folder structure - 🔐 **Secure by default** Configured with CORS, dotenv, and Helmet - 🔌 **MongoDB ready** Pre-wired database connection - 📦 **Lightweight** Only essential dependencies included --- ## 📦 Installation ### Quick Start (Recommended) ```bash npx create-mern-backend@latest ``` --- ### Global Installation ```bash npm install -g create-mern-backend create-mern-backend ``` ## Project Structure 🌳 ``` my-mern-backend/ ├── config/ └── db.js # MongoDB connection config ├── controllers/ # Route controllers ├── models/ # Mongoose models ├── routes/ # API route definitions ├── middlewares/ # Custom middleware ├── utils/ # Utility functions ├── .env # Environment variables ├── .gitignore # Git ignore rules └── server.js # Express server entry point ``` ## Generated Configuration ⚙️ ### server.js ```javascript const express = require("express"); require("dotenv").config(); const app = express(); // Middleware app.use(express.json()); app.use(cors()); // Database connection require("./config/db")(); // Basic route app.get("/", (req, res) => res.send("MERN Backend Running")); const PORT = process.env.PORT || 5000; app.listen(PORT, () => console.log(`Server running on port ${PORT}`)); ``` ### .env Template ```env # Server Configuration PORT=5000 # MongoDB MONGO_URI=your_mongodb_connection_string # Authentication JWT_SECRET=your_random_secret_key JWT_EXPIRE=30d ``` ## Development Scripts 🛠️ After scaffolding: ```bash cd your-project-name npm install npm start ``` ## Why Use This? 🤔 - Saves hours of manual setup - Implements industry best practices - Easily extensible architecture - Perfect for: - Prototyping - Hackathons - Production applications - Learning MERN stack ## Contributing 🤝 Pull requests are welcome! Please open an issue first to discuss changes. ## License 📄 MIT © [Vikash Bharal](https://github.com/Vikash4110) --- ``` ```