node. js Getting Started Tutorial--How to implement file upload function

Source: Internet
Author: User

  Zhanhailiang Date: 2014-11-16

This article describes how to use node. js to implement file upload functionality.

1. Initializing project information: NPM Init

[Root@~/Wade/Nodejs/Nodejs-upload-image-demo]# NPM InitThis utility would walk you through creating a Package.json file. It is covers the most common items, and tries to guess sane defaults. See`Npm HelpJson`  forDefinitive documentation on these fieldsand exactly what they do. Use`NpmInstall <Pkg>--save`Afterwards toInstallA package Andsave it asA dependencyinchThe Package.json file. Press ^c at any TimeTo Quit.name:(Nodejs-upload-image-demo)Version(1.0.0)Description:how to use node. js to upload a imageentry point:(Index.js) TestCommandgitRepository(Https//Github.com/Billfeller/Nodejs-upload-image-demo.git)Keywords:author:billfellerlicense:(Isc)Mitabout toWriteTo/Root/Wade/Nodejs/Nodejs-upload-image-demo/Package.json:{  "Name":"Nodejs-upload-image-demo","Version":"1.0.0","description":"How to use node. js to upload an image","Main":"Index.js","Scripts":{    "Test":"echo \"error:no test specified\ " && exit 1"  },"Repository":{    "Type":"Git","url":"Https://github.com/billfeller/nodejs-upload-image-demo.git"  },"Author":"Billfeller","License":"MIT","Bugs":{    "url":"Https://github.com/billfeller/nodejs-upload-image-demo/issues"  },"Homepage":"Https://github.com/billfeller/nodejs-upload-image-demo"}Is this OK?(Yes) Yes

2. Modify the Package.json, configure the start command:

"Scripts": {     "start": "Node Index.js"},

3. Install the Dependent module: NPM install Formidable–save

4. Function Realization:

    • index.js--Unified portal, including request processor registration;
    • server.js--server module, including server creation, listener requests, execution routing strategy,
    • router.js--routing policy, routed to the appropriate processor for request processing according to the request URL,
    • requesthandler.js--request processor;
  Complete source code See: Https://github.com/billfeller/nodejs-upload-image-demo

5. Start the server:

[Root@~/Wade/Nodejs/Nodejs-upload-image-demo]# NPM Start>Nodejs-upload-image-demo@1.0.0 start/Root/Wade/Nodejs/Nodejs-upload-image-demo>Node Index.js server is starting

6. Access and upload images via the browser:


6. Reference:

    • Node Getting Started
    • Nodebeginner

node. js Getting Started Tutorial--How to implement file upload function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.