Getting started with Node. js-how to upload a node. js File

Source: Internet
Author: User

Getting started with Node. js-how to upload a node. js File

Author: zhanhailiang Date:

This article describes how to use Node. js to upload files.

1. initialize the project information: npm init

[root@~/wade/nodejs/nodejs-upload-image-demo]# npm initThis utility will walk you through creating a package.json file.It only covers the most common items, and tries to guess sane defaults. See `npm help json` for definitive documentation on these fieldsand exactly what they do. Use `npm install <pkg> --save` afterwards to install a package andsave it as a dependency in the package.json file. Press ^C at any time to quit.name: (nodejs-upload-image-demo) version: (1.0.0) description: how to use node.js to upload an imageentry point: (index.js) test command: git repository: (https://github.com/billfeller/nodejs-upload-image-demo.git) keywords: author: billfellerlicense: (ISC) MITAbout to write to /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 package. json and configure the startup command:

"scripts": {     "start": "node index.js" },

3. install the dependency module: npm install formidable-save

4. function implementation:

  • Index. js-Unified entry, including request processor registration;
  • Server. js-server module, including server creation, request listening, and route policy execution;
  • Router. js-routing policy, which routes requests to the corresponding processor based on 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 through a browser:


6. refer:

  • Node entry
  • Nodebeginner

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.