Nodejs Express GET POST Multipart request handling example

Nodejs Express GET POST Multipart request handling example

Create a new with nodejs and express (check this post for how to create node express project)

Pr-requirements

  1. create an empty folder in root of your application
  2. install requires node packages (I have added all the node packages in package.json so you can simply run npm install it will take care of this)

index.js this is my app entry point.

routes.js :- I have made a separate rout file that’s why the routs.js file (Check this post for how to make separate rout file) otherwise you can directly add this code into your entry point file (in my case index.js)

I am using the multer node package for handing multipart request

home.html

package.json

It is ready open your browser and test it

nodefileupload

You can see the file is uploaded, but it is using some random name for the file.

For changing file name we can make a small configuration changes in routs.js. Insted of  ‘var upload = multer({ dest: ‘./uploads/’ });’ add the new configuration settings

 

 

ref :

http://wiki.workassis.com/installing-express-with-nodejs/

http://wiki.workassis.com/nodejs-express-separate-routes/

https://www.npmjs.com/package/multer

  Like
Author: bm on August 19, 2016
Category: Express, NodeJs
Tags: , , , , , ,

Your comment:

Your Name

Comment:




Last articles