{"action":"opened","issue":{"url":"https://api.github.com/repos/hungeraibin/blog/issues/91","repository_url":"https://api.github.com/repos/hungeraibin/blog","labels_url":"https://api.github.com/repos/hungeraibin/blog/issues/91/labels{/name}","comments_url":"https://api.github.com/repos/hungeraibin/blog/issues/91/comments","events_url":"https://api.github.com/repos/hungeraibin/blog/issues/91/events","html_url":"https://github.com/hungeraibin/blog/issues/91","id":305851768,"number":91,"title":"模块化的开发流程","user":{"login":"hungeraibin","id":29303882,"avatar_url":"https://avatars0.githubusercontent.com/u/29303882?v=4","gravatar_id":"","url":"https://api.github.com/users/hungeraibin","html_url":"https://github.com/hungeraibin","followers_url":"https://api.github.com/users/hungeraibin/followers","following_url":"https://api.github.com/users/hungeraibin/following{/other_user}","gists_url":"https://api.github.com/users/hungeraibin/gists{/gist_id}","starred_url":"https://api.github.com/users/hungeraibin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hungeraibin/subscriptions","organizations_url":"https://api.github.com/users/hungeraibin/orgs","repos_url":"https://api.github.com/users/hungeraibin/repos","events_url":"https://api.github.com/users/hungeraibin/events{/privacy}","received_events_url":"https://api.github.com/users/hungeraibin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-16T09:13:26Z","updated_at":"2018-03-16T09:13:26Z","closed_at":null,"author_association":"OWNER","body":"## 模块的分类\r\n- 文件模块\r\n  + 就是我们自己写的功能模块文件\r\n- 核心模块\r\n  + Node平台自带的一套基本的功能模块，也有人称之为Node平台的API\r\n- 第三方模块\r\n  + 社区或第三方个人开发好的功能模块，可以直接拿回来用\r\n\r\n## 模块化的开发流程\r\nnew创建模块 => module.exports导出成员 => require载入模块 => use使用模块\r\n\r\n## 模块内全局环境（伪）\r\n- 我们在之后的文件操作中必须使用**绝对路径**\r\n-  __dirname\r\n  + 用于获取当前文件所在目录的完整路径\r\n  + 在 REPL 环境无效\r\n- __filename\r\n  + 用来获取当前文件的完整路径\r\n  + 在 REPL 环境同样无效\r\n```js\r\n// 获取当前脚本所在目录路径\r\nconsole.log(__dirname)\r\n\r\n// 文件路径\r\nconsole.log(__filename)\r\n\r\nconst fs = require('fs')\r\n\r\n// 所有的文件操作都必须是绝对路径（物理路径）\r\nfs.readFile(__dirname + '/../list.md', 'utf8', (error, content) => {\r\n  if (error) {\r\n    throw error\r\n  }\r\n  console.log(content)\r\n})\r\n```\r\n- module\r\n  + 模块对象\r\n- exports\r\n  + 映射到 module.exports的别名"}}
{"actor":{"display_login":"hungeraibin"}}