Express js tutorial for beginners in hindi 2024
Express.js is a popular web application framework for Node.js. It allows you to build web applications quickly and efficiently. This tutorial will help beginners learn how to use Express.js in Hindi in 2024.
Upload File using Multer
Multer is a middleware for handling file uploads in Node.js. It makes it easy to upload files to your server. Here’s how you can use Multer with Express.js:
Step 1: Install Multer
First, you need to install Multer using npm. Run the following command in your terminal:
npm install multer
Step 2: Use Multer in your Express.js app
Once Multer is installed, you can use it in your Express.js app. Here’s an example of how to upload a file using Multer:
const express = require('express'); const multer = require('multer'); const app = express(); const storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, 'uploads/') }, filename: function (req, file, cb) { cb(null, file.originalname) } }) const upload = multer({ storage: storage }) app.post('/upload', upload.single('file'), (req, res) => { res.json({ message: 'File uploaded successfully' }); }) app.listen(3000, () => { console.log('Server started on http://localhost:3000'); })
With this code, you can upload a file to the server by sending a POST request to the /upload endpoint with a file field in the request body.
Conclusion
In this tutorial, we learned how to use Multer to upload files in an Express.js app. Multer is a powerful tool that makes handling file uploads easy. I hope this tutorial was helpful for beginners learning Express.js in Hindi in 2024.
Very nice
nice content sir…kindly please finish this playlist sir…waiting to complete….thank you in advance 🙏
Thanks for uploading this video
Plz sir next video code de do
sir github link kaha hai ?
Wow nice
❤
Thanks for upload this video