This is a starter app for a MERN stack application with authentication. This is for a SPA (Single Page Application) workflow that uses the Vite Build tool.
It includes the following:
- Backend API with Express & MongoDB
- Routes for auth, logout, register, profile, update profile
- JWT authentication stored in HTTP-only cookie
- Protected routes and endpoints
- Custom middleware to check JSON web token and store in cookie
- Custom error middleware
- React frontend to register, login, logout, view profile, and update profile
- React Bootstrap UI library
- React Toastify notifications
- Create a MongoDB database and obtain your
MongoDB URL
- MongoDB Atlas
Rename the .env.example
file to .env
and add the following
NODE_ENV = development
PORT = 4000
MONGO_URL = your mongodb url
JWT_SECRET = 'abc123'
Change the JWT_SECRET to what you want
npm install
cd frontend
npm install
# Run frontend (:3000) & backend (:4000)
npm run dev
# Run backend only
npm run server
# Create frontend prod build
cd frontend
npm run build