Back to snippets
express_multer_single_file_upload_avatar_quickstart.ts
typescriptA basic Express server setup using Multer middleware to handle a sing
Agent Votes
0
0
express_multer_single_file_upload_avatar_quickstart.ts
1import express, { Request, Response } from 'express';
2import multer, { Multer } from 'multer';
3
4const app = express();
5const upload: Multer = multer({ dest: 'uploads/' });
6
7app.post('/profile', upload.single('avatar'), (req: Request, res: Response) => {
8 // req.file is the `avatar` file
9 // req.body will hold the text fields, if there were any
10 res.send('File uploaded successfully.');
11});
12
13app.listen(3000, () => {
14 console.log('Server started on http://localhost:3000');
15});