百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

mern-stack-example

> 前端框架
开源

使用 MongoDB Atlas、Express、React 和 Node.js (MERN) 的全栈 CRUD 应用程序。涵盖 REST API、MongoDB 驱动程序和 React Router。

400 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用 MongoDB Atlas、Express、React 和 Node.js (MERN) 的全栈 CRUD 应用程序。涵盖 REST API、MongoDB 驱动程序和 React Router。

MERN Stack Example: Employee Records App (MongoDB Atlas, Express, React, Node.js)

A full-stack CRUD application built with MongoDB, Express, React, and Node.js (MERN).

Companion code for the MERN Stack Tutorial and video walkthrough.

Project Overview

This project demonstrates an employee record tracker:

  • Create records
  • Read records from MongoDB Atlas
  • Update records
  • Delete records

The React app in mern/client calls an Express API in mern/server, and data is stored in MongoDB Atlas.

MERN Stack Architecture

…

Stack:

  • Frontend: React 18, Vite, Tailwind CSS, React Router
  • Backend: Node.js, Express 4, MongoDB Node.js Driver 6
  • Database: MongoDB Atlas (employees.records collection)

Project Structure

mern/
   client/   # React + Vite frontend
   server/   # Express API + MongoDB integration

Prerequisites

  • Node.js 20+
  • npm 9+
  • A free MongoDB Atlas cluster

Quick Start and MongoDB Setup

bash
# 1) Clone
git clone https://github.com/mongodb-developer/mern-stack-example.git
cd mern-stack-example

# 2) Create server environment file
cp mern/server/config.env.example mern/server/config.env

Update mern/server/config.env with one of the following ATLAS_URI values:

Atlas cluster:

env
ATLAS_URI=mongodb+srv://:@.mongodb.net/
PORT=5050

If you are new to Atlas, use the Atlas quick start guide and then paste your connection string into ATLAS_URI.

Optional: seed sample data:

bash
cd mern/server && node seed.js

Start the backend API:

bash
cd mern/server
npm install
npm start

Start the frontend in a second terminal:

bash
cd mern/client
npm install
npm run dev

Open http://localhost:5173.

GitHub Codespaces and Dev Containers

GitHub Codespaces is an easy and fast way to get this project running without installing anything locally. It uses a dev container, which is a Docker environment configured for development.

REST API Endpoints

Base URL: http://localhost:5050

Method Endpoint Description
GET /record Retrieve all records
GET /record/:id Retrieve one record by ID
POST /record Create a record
PATCH /record/:id Update a record
DELETE /record/:id Delete a record

Example request body for create or update:

json
{
   "name": "Jane Smith",
   "position": "Developer",
   "level": "Senior"
}

MongoDB Features Demonstrated

Feature Where
MongoDB Node.js Driver mern/server/db/connection.js
CRUD operations mern/server/routes/record.js
MongoDB Atlas ATLAS_URI in config.env
Server API version ServerApiVersion.v1 in connection.js

Troubleshooting

Cannot connect to MongoDB Atlas

  • Verify ATLAS_URI in mern/server/config.env
  • Confirm your database user credentials are correct in mern/server/config.env
  • Confirm your IP is in Atlas Network Access

Backend fails to start

  • Check Node version: node --version
  • Confirm mern/server/config.env exists
  • Reinstall dependencies in mern/server: npm install

Frontend shows empty data

  • Confirm backend is running on :5050
  • Open browser dev tools and check network requests
  • Confirm records exist in Atlas (or run node seed.js in the server folder)

Port already in use

  • Change PORT in mern/server/config.env, or stop the process using :5050

Community and Support

  • Use GitHub Issues for bugs and feature requests
  • Use MongoDB Community Forums for general MongoDB questions

Additional Resources

  • MERN Stack Tutorial
  • MongoDB Atlas Docs
  • MongoDB Node.js Driver Docs

License

Apache 2.0

Disclaimer

This repository is for educational use and is not a supported MongoDB product.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptexpressexpressjsjavascriptmongodb

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架