Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

File Uploading Code using Node and Express Js

Step1st:-   Create Front End  File using HTML or ,ANGULAR,


      <title>File Uploading Form</title>

      <h3>File Upload:</h3>
      Select a file to upload: <br />
      <form action = "http://localhost:3000/uploadfile" method = "POST"
         enctype = "multipart/form-data">
         <input type="file" name="myFile" size="50" />
         <br />
         <input type = "submit" value = "Upload File" />

Step 3rd:-
const express = require('express')
const bodyParser= require('body-parser')
const multer = require('multer');
const app = express()
 app.use(bodyParser.urlencoded({extended: true}))

var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'uploads')
  filename: function (req, file, cb) {
    cb(null, file.fieldname + '-' +

var upload = multer({ storage: storage })

app.get('/', function(req, res) {
    res.json({ message: 'WELCOME' }); 
});'/uploadfile', upload.single('myFile'), (req, res, next) => {
  const file = req.file
  if (!file) {
    const error = new Error('Please upload a file')
    error.httpStatusCode = 400
    return next(error)
app.listen(3000, () => console.log('Server started on port 3000'));


Post a Comment

POST Answer of Questions and ASK to Doubt

Previous Post Next Post