note.js 笔记第一课

第一部分:环境安装
    >1.下载安装nodejs
        >01.http://www.nodejs.org/zh-cn/
        >02.http://www.nodejs.org/en/
        >03.msi版本的用来安装
        >04.tar.gz版本用来配置webstorm
    >2.了解npm包管理工具
        >01.npm初始化
            >001. npm init
            >002.文件夹名字不可包含大写字母
            >003.文件夹名字不可有空格
        >02.查看安装包:
            >001. npm ls
            >002. npm ls -g
        >03.下载bower包管理工具
            >001. npm install bower -g
        >04.特定版本(bower info 包名)查看包的版本信息
            >001. npm install body-parser@1.15.1 --save
                加--save有两个作用
                    0001->将下载的包的信息添加到package.json文件里
                    0002->将下载下来包放到当前项目目录的node_modules

        >05.dev结点(只在开发时用到的模块信息放到dev节点)
            >001. npm install body-parser --save-dev
        >06.批量拉包
            >001.npm install ==》dependencies和devDependencies
            >002.npm install --prod ==》dependencies
            >003.npm install --only=dev ==>devDependencies
        >07.移除包
            >001.npm uninstall packageName
            >002.npm uninstall packageName -g


            (用bower必须要下载git)

-----------------------------------------------------------------------------------------------
第二部分:hello-world
    >1.在cmd或者git bash里运行:node 01.js
        >01.如果被占用,则把代理清除
            >001.npm config set proxy null
    >2.通过npm下载web框架express

-----------------------------------------------------------------------------------------------
第三部分:基本组件1:console
    >1.console.log:打印日志
    >2.console.info:打印信息
    >3.console.warn:打印警告
    >4.console.error:打印错误
    >5.console.dir:打印信息,类型
    >6.console.time('tagName'):开始计时 ****
    >7.console.timeEnd('tagName'):结束计时****
    >8.console.trace():跟踪函数执行过程
    >9.console.assert(表达式):断言****
-----------------------------------------------------------------------------------------------
第四部分:HTTP
    >1.引入模块http
        >01.require('http')
    >2.创建服务器:createServer
        >01.server=http.createServer(function(req,res){});
            >01.writeHead:响应头
                >001.res.writeHead=object
                >002.200-配置
                    >01:text/html:以html形式返回
                    >02:text/json:以json格式返回
                    >03:text/xml:以xml格式返回
                    >04:text/plain:原样返回
                    >05:charset=utf-8
                    >06:'txt': 'text/plain',
                         'html': 'text/html',
                         'css': 'text/css',
                         'xml': 'application/xml',
                         'json': 'application/json',
                         'js': 'application/javascript',
                         'jpg': 'image/jpeg',
                         'jpeg': 'image/jpeg',
                         'gif': 'image/gif',
                         'png': 'image/png',
                         'svg': 'image/svg+xml'
                >003.301-{'Location':'新地址'}
        >02.监听:listen
            >01.server.listen(port,hostname,callback);
            >02.port:监听端口
            >03.hostname:监听主机名
            >04.callback:回掉函数
                >001.function(err){console.log(err);}
-----------------------------------------------------------------------------------------------
第六部分:练习
    >1.//创建一个监听 on/addListener
           //打印出监听的函数数量:ListenerCount
           //移除掉监听函数,removeListener
       //执行监听 emit

原文地址:https://www.cnblogs.com/lwwnuo/p/7651601.html