Node.js實現文件上傳功能

jopen 10年前發布 | 65K 次閱讀 Node.js 文件上傳

  作者:zhanhailiang 日期:2014-11-16

本文將介紹如何使用Node.js實現文件上傳功能。

1. 初始化項目信息:npm init

[root@~/wade/nodejs/nodejs-upload-image-demo]# npm init
This 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 fields and exactly what they do.

Use npm install <pkg> --save afterwards to install a package and save 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 image entry point: (index.js) test command: git repository: (https://github.com/billfeller/nodejs-upload-image-demo.git) keywords: author: billfeller license: (ISC) MIT About 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": "

Is this ok? (yes) yes</pre>

2. 修改package.json,配置啟動命令:

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

3. 安裝依賴模塊:npm install formidable –save

4. 功能實現:

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!