# nodejs_study **Repository Path**: program_bell/nodejs_study ## Basic Information - **Project Name**: nodejs_study - **Description**: nodejs学习项目 - **Primary Language**: JavaScript - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-06-23 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # nodejs_study #### 项目介绍 nodejs学习项目 #### 软件架构 软件架构说明 #### 安装教程 1. 安装 Express 安装 Express 并将其保存到依赖列表中: $ cnpm install express --save 以上命令会将 Express 框架安装在当前目录的 node_modules 目录中, node_modules 目录下会自动创建 express 目录。以下几个重要的模块是需要与 express 框架一起安装的: body-parser - node.js 中间件,用于处理 JSON, Raw, Text 和 URL 编码的数据。 cookie-parser - 这就是一个解析Cookie的工具。通过req.cookies可以取到传过来的cookie,并把它们转成对象。 multer - node.js 中间件,用于处理 enctype="multipart/form-data"(设置表单的MIME编码)的表单数据。 $ cnpm install body-parser --save $ cnpm install cookie-parser --save $ cnpm install multer --save 安装完后,我们可以查看下 express 使用的版本号: $ cnpm list express /data/www/node └── express@4.15.2 -> /Users/tianqixin/www/node/node_modules/.4.15.2@express 2. xxxx 3. xxxx #### 使用说明 1. API文档路径:http://nodejs.cn/api/globals.html#globals_dirname Express中文API文档:https://www.runoob.com/w3cnote/express-4-x-api.html 2. xxxx 3. xxxx 4.文件权限参数设置参考表 Flag 描述 r 以读取模式打开文件。如果文件不存在抛出异常。 r+ 以读写模式打开文件。如果文件不存在抛出异常。 rs 以同步的方式读取文件。 rs+ 以同步的方式读取和写入文件。 w 以写入模式打开文件,如果文件不存在则创建。 wx 类似 'w',但是如果文件路径存在,则文件写入失败。 w+ 以读写模式打开文件,如果文件不存在则创建。 wx+ 类似 'w+', 但是如果文件路径存在,则文件读写失败。 a 以追加模式打开文件,如果文件不存在则创建。 ax 类似 'a', 但是如果文件路径存在,则文件追加失败。 a+ 以读取追加模式打开文件,如果文件不存在则创建。 ax+ 类似 'a+', 但是如果文件路径存在,则文件读取追加失败。 #### 参与贡献 1. Fork 本项目 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 码云特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目 5. 码云官方提供的使用手册 [http://git.mydoc.io/](http://git.mydoc.io/) 6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) #### 注意点 fs.writeFile 并不一定是覆盖原来文件内容,而是取决于打开文件时带的 flags。如果是通过 writeFile 直接打开文件默认是 w 模式,但是也可以通过 open 打开文件指定模式,然后通过 writeFile 来写文件,比如: fs.open(fileName, "a+", function(err, fd){ if (err) { return console.error(err); } fs.writeFile(fd, "bb", function(err){ if (err){ return console.error(err); } }); }); 上面的 writeFile 是追加模式写文件。