Backend Foundation is my personal backend learning repository where I document and practice core backend development concepts by building real-world projects using Node.js, Express.js, and MongoDB. This repository tracks my journey of learning server-side development, authentication, APIs, database integration, and scalable backend architecture.
Follow these terminal commands to set up the initial backend project structure from scratch.
mkdir backend-foundation && \
cd backend-foundationnpm initnpm install --save-dev --save-exact prettiermkdir public src && \
mkdir public/images && \
cd src && \
mkdir controllers models routes middlewares utils db validators && \
touch app.js index.js && \
touch controllers/.gitkeep models/.gitkeep routes/.gitkeep middlewares/.gitkeep utils/.gitkeep db/.gitkeep validators/.gitkeep && \
cd .. && \
touch public/images/.gitkeep .env .gitignore .prettierrc .prettierignorenode_modules/
.env
.vscode/
.DS_Store
dist/{
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": false,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "always"
}node_modules
dist
.env
package-lock.jsonInstall dotenv to manage environment variables from a .env file.
npm i dotenvInstall nodemon to automatically restart the server when file changes are detected.
npm i nodemonInstalls Express framework for building backend APIs and handling routes.
npm i expressEnables CORS for handling cross-origin requests.
npm i corsInstalls Mongoose for interacting with MongoDB using schemas and models.
npm i mongooseInstalls bcrypt for hashing and securing user passwords.
npm i bcryptInstalls JSON Web Token for authentication and secure token generation.
npm i jsonwebtokenProvides cryptographic functionality for hashing, encryption, and secure token generation.
npm i cryptoInstalls Nodemailer for sending emails from the application.
npm i nodemailerInstalls Mailgen for generating beautiful email templates.
npm i mailgenInstalls express-validator for validating and sanitizing incoming request data.
npm i express-validatorInstalls cookie-parser for parsing cookies from incoming client requests.
npm i cookie-parserInstalls Resend for handling and sending transactional emails.
npm install resendAll request bodies must use:
Content-Type: application/jsonRequest Body:
{
"username": "testuser",
"email": "testuser@example.com",
"password": "TestPass123"
}Verify a user's email address using the verification token and email received through the URL parameters
Request Body:
{
"verificationToken:": "EMAIL_VERIFICATION_TOKEN"
}Send a new email verification link by using the expired token and email received through the URL parameters when the previous verification token has expired. Request Body:
{
"expiredToken": "EXPIRED_TOKEN",
"email": "testuser@example.com"
}Request Body:
{
"username": "testuser",
"email": "testuser@example.com",
"password": "TestPass123"
}Request Body:
{
"email": "testuser@example.com"
}Reset the user's password using the reset token received via email.
Request Body:
{
"token": "RESET_TOKEN_FROM_EMAIL",
"newPassword": "NewPass123"
}Protected Route:
Authorization: Bearer <access_token>Request Body:
{
"oldPassword": "OldPass123",
"newPassword": "NewPass123"
}Retrieve the profile details of the currently authenticated user using the access token.
Protected Route:
Authorization: Bearer <access_token>OR
Cookie: accessToken=<httpOnly-cookie>Check whether the server is running and responding correctly.
Request Body:
{
"refreshToken": "your_refresh_token"
}OR
Cookie: accessToken=<httpOnly-cookie>Protected Route:
Authorization: Bearer <access_token>OR
Cookie: accessToken=<httpOnly-cookie>