An open API service indexing awesome lists of open source software.

https://github.com/devjubayr/nextube_backend

A professional backend structure for industry level application.
https://github.com/devjubayr/nextube_backend

Last synced: 6 days ago
JSON representation

A professional backend structure for industry level application.

Awesome Lists containing this project

README

          

# NodeJS_Backend

A basic Node.js backend boilerplate setup.

---

## 🚀 Project Setup Step by Step

### 1. Initialize Project

```bash
npm init -y
```

### 2. Install Dev Dependencies

```bash
npm i -D nodemon
```

> `nodemon` reloads the server automatically when code changes. The `-D` flag ensures it is installed as a dev dependency only.

### 2.5. Install Dev Dependencies

> Set `"type": "module"` in package.json file

### 3. Configure Git

- Create a `.gitignore` file to prevent pushing unnecessary files (e.g., `node_modules`, `.env`).
- Use this [Gitignore Generator](https://mrkandreev.name/snippets/gitignore-generator/#).

### 4. Project Structure

```bash
In root: public/temp/.gitkeep
In src/: index.js app.js constants.js
Folders Inside /src: controllers models routes middlewares db utils
```

### 5. File Naming Convention

- Controllers → `example.controller.js`
- Models → `example.model.js`
- Routes → `example.route.js`
- Middlewares → `example.middleware.js`

### 6. Add .env and .env.sample

- Create two file .env for local environment variables
- And .env.sample for uploading to github (Don't share privet key or any code here)

### 7. Install prettier

- Prettier removes bike-shedding about code style, keeps your codebase consistent, and lets you focus on writing logic, not spacing.
- Create `.prettierrc` for telling formats
- Create `.prettierignore` for ignore file where we don't need the feature
- > Only in Dev "-D": `npm i -D prettier`

---

## 📂 Folder Structure

```
project-root
│── node_modules
│── public
│ └── temp
│ └── .gitkeep
│── src
│ ├── app.js
│ ├── index.js
│ ├── constants.js
│ ├── controllers/
│ ├── models/
│ ├── routes/
│ ├── middlewares/
│ ├── db/
│ └── utils/
│── package.json
│── .gitignore
```

---

## 🛠️ Scripts

In `package.json`, add:

```json
"scripts": {
"start": "node src/index.js",
"dev": "nodemon src/index.js"
}
```

Run in development mode:

```bash
npm run dev
```

---

✅ Setup complete! Now Install techs based on need.

## Top important packages

- mongodb
- mongoose
- express
- dotenv
- cors