美文网首页
Node笔记 - Segment

Node笔记 - Segment

作者: _Wake | 来源:发表于2016-11-22 23:16 被阅读34次

    第一章
    一、 Node.js Express 框架
    1.全局安装 : npm install -g express
    注:如果出现版本问题:epress不是内部或外部命令
    执行: npm install -g express-generator
    测试安装:express -h 命令可列出全部命令

    2.创建项目及文件夹
    express -e segment
    打开package.json
    若没有以下两项则添加:

    //node.js中间件,处理json,text,Raw和URL编码的数据 
    "body-parser": "~1.15.2",  
    //解析Cookie的工具,通过req.cookies取到传来的cookie,并转为对象
    "cookie-parser": "~1.4.3",
    

    3.安装

    cd segment
    npm install
    

    注:若出现错误,可尝试 npm cache clear ,再安装

    4.添加必要的中间件
    npm install multer --save
    multer: 用户处理enctype="multipart/form-data"的表单数据

    5.端口修改在 bin/ww
    启动 npm start

    第二章
    1.部署页面html css
    ... ...
    2.express接收参数

    req.query['name']     // 接受get和地址栏传来的参数
    req.body['name']      // 接受post传来的参数
    

    第三章:注册
    1,单例模式连接池

    //ConnPool.js
    var mysql = require('mysql');
    module.exports = (function() {
        var pool = mysql.createPool ({
            host: 'localhost',
            .....
        });
        pool.on('connection', function(connection){
            connection.query('SET SESSION auto_increment_increment=1');
        })                             
    })();
    

    相关文章

      网友评论

          本文标题:Node笔记 - Segment

          本文链接:https://www.haomeiwen.com/subject/cllupttx.html