zoukankan      html  css  js  c++  java
  • Node04

    1、介绍、配置、安装

      (01)、Express介绍:

            Express是一个基于Node.js平台的极简、灵活的Web应用平台,提供了一系列强大的特性,

            帮助创建各种 Wed 和移动设备应用。

          Express性能:

            Express 不对 Node.js 已有的特性进行二次抽象,我们只是在它之上扩展了 Web 应用所需的基本功能。

      (02)、Express 安装  =>   cnpm  install express

            ①、引入express:     const express = require('express');

            ②、调用express函数:   var server=express();

              (01)、express基本用法:;

                    处理请求 => server.use('/', function(req, res){}); 

                    server.use('地址',function(req,res){res.send('abc';res.end())}) ;

                        //地址:可以是(/)根路径,也可以是文件路径(a.html);write改成send。同样都是输出的意思,想前台发送信息

                        //req、res和原生的不一样是经过express封装过后的

                        //send增强了write,可以发送对象。

              (02)、GET请求 =>  server.get('/', function(req, res){});  方法同use

                    *注意:地址前没有逗号,前端ajax调用接口的时候,url的地址和 server.get('/',...)地址一致

              (03)、POST请求 =>  server.post('/', function(req, res){});

              (04)、express中间件  =>  express-static

                    server.use(expressStatic('./www'));//读取静态文件,需要告诉从哪读

              (05)、express(GET)提供了req.query()方法;用来解析数据,与原生node里的url.parse()和querystring.parse();相同

                (06)、express中间件  => body-parser(容纳POST 数据)

                    server.use(bodyParser.urlencoded({ extended, limit }));//数据解析

                       extended:扩展模式

                       limit : 限制

            ③、监听:        server.listen(8080);

            

  • 相关阅读:
    删除Tomcat服务及其它注意
    下拉菜单被js图片挡住
    There are no resources that can be added or removed from the server
    Mysql存中文值乱码
    myeclipse的项目导入到eclipse下,com.sun.org.apache.commons.beanutils.BeanUtils不能导入
    No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
    winServer2003除默认端口外的其他端口只能本地访问,关闭防火墙即可
    Oracle 11.2.0.3 on windows 2008 r2
    windows2008 r2 卸载GI
    初始化参数(Initialization Parameter)知识合集 based on 11g
  • 原文地址:https://www.cnblogs.com/patriot/p/8000738.html
Copyright © 2011-2022 走看看