# Backend Class 2.

Love Babber (BD-2)

### Send Data in DB and see folder structure.

### Some steps of creating a folder.

* Create a folder on the desktop
    
* open it into in VS code
    
* Open Vs code terminal
    
* Initialization of the packege.json file using `npm init -y` command
    
* Create a file name `index.js`
    
* Now install express js using `npm i express`
    
* Now install Nodemon using `npm i nodemon`
    
* Now install env files to set the environment using `npm i dotenv`
    
* Create 4 different folders <mark>(routes, config, controller, models)</mark>
    
* Create a `.env` file in the <mark>routes folder</mark>
    
* Create a `database.js` file in the <mark>config folder</mark> to connect our DB to the server
    
* Create a `createTodo.js` file in the <mark>controller folder</mark> to control the data
    
* Create a `todo.js` file in the <mark>models' folder</mark> to create a DB Schema
    
* Create a `todos.js` file in the <mark>routes folder</mark> to define the API Routes
    

### See the code example to connect the db to the server.

> Index.js file code

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689072845592/109b1387-93a1-44fd-b261-39cd322bee8d.png align="center")

> database.js file code (Connect to DB)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689072921152/2386a188-955d-4e97-920f-80f620d9b7bf.png align="center")

> todo.js file code (define Schema)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689073015410/97dd0de7-dd8f-4329-b8a1-edcbf99e25c1.png align="center")

> todos.js file (Creating routes)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689073099849/97d67d1b-c292-4f13-a9ae-90ac25833852.png align="center")

> createTodo.js (Doing funclatity)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689073177022/7b17a946-19c9-44a1-92cc-a2ac41273c2a.png align="center")

> .env file

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689073227752/f527fe92-0449-46eb-9329-bb1c0f29cb20.png align="center")

> Package.json file

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689073278342/6b03e132-2765-4fb4-88f5-1832603dccd7.png align="center")
