dbackend
v1.0.10
Published
Modular backend utility library
Downloads
48
Readme
🧠 THE Backend (by Devansh)
THE Backend (dbackend) is a modular, ready-to-use backend toolkit that simplifies user authentication, email handling, middleware management, and MongoDB integration. Designed for rapid backend development with clean structure and extensibility in mind.
🚀 Installation
npm install dbackend📦 Features
- ✅ MongoDB connection with Mongoose
- ✅ Authentication system (Signup, Signin, JWT, Email Verification, Password Reset)
- ✅ Built-in JWT middleware
- ✅ Mailer integration using Nodemailer
- ✅ Plug-and-play Express middlewares (CORS, JSON, URL Encoded)
🛠️ Usage
1. Setup
const express = require("express");
const backend = require("dbackend"); // THE Backend
const User = require("./models/User"); // Define your Mongoose User model2. Connect to MongoDB
backend.mongodb({
url: "mongodb://localhost:27017/mydb",
});3. Setup Mailer (Optional)
const mailer = backend.mailer({
service: "Gmail",
auth: {
user: "[email protected]",
pass: "yourpassword",
},
});
await mailer.sendMail({
to: "[email protected]",
subject: "Welcome!",
text: "Thank you for signing up!",
html: "<h1>Thank you for signing up!</h1>",
});4. Setup Authentication
const auth = backend.auth({
jwtSecret: "your_jwt_secret",
UserModel: User,
mailer: mailer, // Optional
});5. Use Middleware
const app = express();
backend.middlewares(app, ["json", "urlencoded", "cors"]);🔐 Auth API Example
// Sign Up
await auth.signup({
email: "[email protected]",
password: "123456",
name: "Dev User",
});
// Sign In
const result = await auth.signin({
email: "[email protected]",
password: "123456",
});
console.log(result.token); // JWT Token
// Middleware Example (Protect Routes)
app.get("/dashboard", auth.middleware(), (req, res) => {
res.send(`Welcome ${req.user.email}`);
});📧 Forgot & Reset Password
await auth.forgotPassword("[email protected]");
// Then on /reset-password route
await auth.resetPassword(tokenFromEmail, "newPassword123");📁 Folder Structure (Example)
your-app/
│
├── models/
│ └── User.js
├── server.js
└── ...🙌 Credits
Developed with ❤️ by Devansh(CodeReb00t)
Feel free to contribute, report issues, or suggest features!
