查看note安装目录:
npm root -gexports的用法这个小项目演示学生,老师,班级以及学校的关系学生
function add(student){ console.log('student name'+student)}exports.add = add//暴露add方法
老师
function add(teacher){ console.log('teacher name'+teacher)}exports.add = add
班级
var teacher = require('./teacher')//引入模块var student = require('./student')function add(teachers,students){ teacher.add(teachers) students.forEach(function(item,index){//不只一个学生,所有需要遍历 student.add(item) })}exports.add = add
node入口文件 index.js
var klass = require('./klass')klass.add('scott',['1','2'])
node index.js 可以将老师名和学生名打印出来
创建学校
var klass = require('./klass')exports.add = function(klasses){ klasses.forEach(function(item,index){ var _klass = item; var teacherName = item.teacherName; var studentName = item.studentName; klass.add(teacherName,studentName) })}
node api
url.parse 默认为falseurl.parse('http://www.baidu.com:30/list?name=we$pwd=23'){ protocol: 'http:', slashes: true, auth: null, host: 'www.baidu.com:30', port: '30', hostname: 'www.baidu.com', hash: null, search: '?name=we$pwd=23', query: 'name=we$pwd=23', pathname: '/list', path: '/list?name=we$pwd=23', href: 'http://www.baidu.com:30/list?name=we$pwd=23' }
url.format
url.format({ protocol: 'http:',.. slashes: true,.. auth: null,.. host: 'www.baidu.com:30',.. port: '30',.. hostname: 'www.baidu.com',.. hash: null,.. search: '?name=we$pwd=23',.. query: 'name=we$pwd=23',.. pathname: '/list',.. path: '/list?name=we$pwd=23',.. href: 'http://www.baidu.com:30/list?name=we$pwd=23' })http://www.baidu.com:30/list?name=we$pwd=23'
url.resolve
url.resolve('http://www.baidu.com:30','/pwd')'http://www.baidu.com:30/pwd'
url.parse(':30/list?name=we$pwd=23',true)
parse传递2个参数
url.parse('//baidu.com'true,true)querystring.stringify()> querystring.stringify({name:'scott',course:['jade','node'],from:''})'name=scott&course=jade&course=node&from='
querystring.parse()反序列化
escape对中文字符进行转意querystring.escape('你是谁《《《')unescape对字符进行反转意querystring.unescape('%E4%BD%A0%E6%98%AF%E8%B0%81%E3%80%8A%E3%80%8A%E3%80%8A')