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 ; }
in scr we make the folder name mkdircontrollers- 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
connection data basecopy the url as well as the password
all logic code of the database connection will write inside the db folder weith name db.js
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 ..
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)
to configure the cors
const app = express()
app.use(cors({ origin : process.env.CORS_ORIGIN, credentials:true })) app.use(express.json({limit:"16kb"})) 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.
at last they get the response
->>
app.get('/insta' , (req, res)=>{
res.send("hey i am available")
})
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
})