Skip to content

rajsingh1301/auths

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Drive App — Node.js + Express + MongoDB

A clean starter for building server-rendered auth flows with EJS and MongoDB. Includes registration, login, cookie-based JWT sessions, and a simple home page.

Highlights

  • Express + EJS: Fast server-rendered pages (views/)
  • MongoDB (Mongoose): Simple User model (models/user.model.js)
  • Auth Ready: Register, Login, JWT in cookies
  • Dotenv: Environment-based configuration

Folder Structure

├─ app.js                  # App entry
├─ config/db.js            # MongoDB connection
├─ models/user.model.js    # User schema
├─ routes/
│  ├─ index.route.js       # Home/Index routes
│  └─ user.route.js        # Auth (register/login)
└─ views/                  # EJS templates
   ├─ home.ejs
   ├─ index.ejs
   ├─ login.ejs
   └─ register.ejs

Prerequisites

  • Node.js 18+
  • MongoDB running locally or a cloud URI

Setup

  1. Install dependencies
npm install
  1. Create a .env file in the project root
MONGO_URI=mongodb://localhost:27017/drive-app
JWT_SECRET=your-super-secret-key
  1. Start the server
npm start      # production
# or
npm run dev    # with nodemon

The app runs at http://localhost:3000.

Available Routes

  • GET / → Index page
  • GET /user/register → Registration page
  • POST /user/register → Create user (validates username, email, password)
  • GET /user/login → Login page
  • POST /user/login → Authenticate; sets token cookie

Tech Stack

  • express, ejs, mongoose
  • bcrypt, jsonwebtoken, cookie-parser
  • express-validator, dotenv

Scripts

{
  "start": "node app.js",
  "dev": "nodemon app.js"
}

Notes

  • JWT is stored in a cookie named token after login.
  • The User model trims fields and validates lengths; passwords are hashed with bcrypt.

Next Steps

  • Add logout route (clear the token cookie)
  • Protect pages using a JWT-check middleware
  • Add flash messages and better form UX in EJS views

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors