0% found this document useful (0 votes)
15 views26 pages

Mern Stack

This document provides a comprehensive guide on setting up a backend using Node.js, Express, and MongoDB. It covers the creation of a server, handling requests and responses, using middleware, and managing environment variables with dotenv. Additionally, it includes instructions for CRUD operations in MongoDB and the installation of necessary packages like nodemon and mongoose.

Uploaded by

Asma Eman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views26 pages

Mern Stack

This document provides a comprehensive guide on setting up a backend using Node.js, Express, and MongoDB. It covers the creation of a server, handling requests and responses, using middleware, and managing environment variables with dotenv. Additionally, it includes instructions for CRUD operations in MongoDB and the installation of necessary packages like nodemon and mongoose.

Uploaded by

Asma Eman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Backend – Node – Express – MongoDB

 Understand [Link]
 npm init -y for [Link] file (project can run without this file)
 staring file -> [Link]
 make file naming [Link]
 to run JS file, use terminal (windows function not work, like alert())
 write command node [Link] (file name)
 nodemon package -> automatically run server, when we save file
it will run
 npm i -g nodemon -> install nodemon -> run anywhere on cmd
 global package exist – c drive -> users-> username-> appdata->
Roaming->npm --- here exist
 Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -> Run on
PowerShell
 This command allow nodemon to run JS file
 Run file nodemon [Link]
 Set in [Link] in “script” tag -> “start” : “nodemon index” -> now ->
npm start (project will run by using this command)

 In [Link] “type”:”commonjs” is by default, which is used to export


using require package
Create file -> [Link]

How to Create Sever in [Link]


Request -> from frontend to backend
 Response -> backend to frontend
 named export (multiple modules can be export)
 Default export (only one module is export)
 We can export variable also.

Change the type : Module - > import and export


Create Sever :

Callback function - > which called in the parameter of some other


function
 When we used in node we use [Link]() function but it will change in
express

 Multiple URLs

[Link]
 Make server using express js
 Third party app -> need to install
 npm I express


 Get method route can run on bowser
 Multiple routes in express

 Get method is used to display data

 Post method -> to secure data, directly not accessible, not run on browser
(like forms data, handle large data, handle files, binary type data handle,
not visible user)

 Install Thunder Client / or Postman


Request Parameter -> data comes from the frontend, and is sent to
backend
 Body -> JSON

 Query -> URL

 Param -> Dynamic value

 All this data we can find in the request parameter

 Body

Explicitly mandatory to mention -> [Link]([Link]()) -> to get JSON


data
Write in body of ThunderClient -> it means data comes from the frontend
and is sent to the backend.
if data is passed in body, it get by request parameter.
- Check first only req using [Link](req), it will show on console of VS

Its comes from the front end

Send a response, to specific values.

Query->
Query data -> mostly used for searching purposes. Data goes with a URL

Params -> dynamic parameter -> Like ID, which is able to change

Response can be handle using status()


Middleware -> between Request and Response

Token example
Multiple Middleware -> is a process which is executed before
some code
Used before main code/process

Middleware on URLs
Connect at route level
Connected at route level not all

.env -> environment variables _> used to store sensitive type


information.
 Install package
 npm I dotenv
 create .env file

Where you used

Add above code


Now it can be used

MONGODB
Time:2-46
CURD in MongoDB
 get can be run on browser
 ? concatenation with id, make it optional

Both values update

If some values need to update, not all

Not allowed same email


- npm I mongoose (install mongoose)

Database connection

Creating model for database


Insert values in database (Write the values in thanudarClient body section)
To retrieve data from database

To delete data
To update values

You might also like