Skip to content

Arpit2singh/Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

starting project with backend

Short Notes : to track the file we use the nodemon

npm i -D nodemon then ad dto the script{ "dev" : nodemon ; }

step 2

in scr we make the folder name mkdir

controllers- main functionality db - how the data base is connected datbase connection logic middlewares - interfering the response and requestion find some data in between models - schema utils -- functionality use agin and again so like mail and more so it is work as function routes -- /jokes , /more tab

step 3

connection data base

copy the url as well as the password

all logic code of the database connection will write inside the db folder weith name db.js

step 4

make sure you use the dotenv.config before the use the function of dbLogic

in the constants we write the dbName == you can write the name of any it will be shown on the data base ..

step 5

make sure the there is module error of js somthing like that

code: 'ERR_MODULE_NOT_FOUND', url: 'file:///D:/learning%20Backend/src/db/db' }

Node.js v22.14.0 [nodemon] app crashed - waiting for file changes before starting...

to checkout more error you have t write the console.log(different error name to identify the part which have the error)

step 6

to configure the cors

const app = express()

to configure the cors use

app.use(cors({ origin : process.env.CORS_ORIGIN, credentials:true }))

to limit the response size from the use

app.use(express.json({limit:"16kb"}))

every space have some meaning so to decode it use the encoder

app.use(express.urlencoded({extended:true , limit :"16kb"}))

it is the middle ware where When a client sends an HTTP request with cookies, they are included in the Cookie header as a string. The cookie parser takes this string and separates the individual cookie name-value pairs.

app.use(cookieParser()) ;

what is the middleware

middleware is the interaction of the system in between the respose said to be middleweare they have 4 tupple (err, req ,res ,next) what is next -> next is the while interaction they will check the authentication , check weather it is admin or not many more thing we can check so it is the hop to htp communication while doing task it will move from onw to another

at last they get the response
->> app.get('/insta' , (req, res)=>{ res.send("hey i am available") })

video 11

fs.unsynclink help us to remove the temp file wich is not uploaded or some error is occured

before intalizing the cloudinary you have to configure the cloudinary ,
then by we use t he async function ,

Multer is a middleware function in Node.js, meaning it sits between the request and the response, intercepting and processing data, in this case, file uploads.
Multer is a middleware function in Node.js, meaning it sits between the request and the response, intercepting and processing data, in this case, file uploads.

      request        middleware                     function 

app.post('/profile', upload.single('avatar'), function (req, res, next) { // req.file is the avatar file // req.body will hold the text fields, if there were any })

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors