zoukankan      html  css  js  c++  java
  • nodeJs学习-06 模块化、系统模块、自定义模块、express框架

    系统模块:http://nodejs.cn/api/events.html

    自定义模块:

      require   请求:引入模块
      module    模块:批量输出
      exports   输出:单独输出
     
     
    express基础应用
    // 下载express  cnpm install express
    const express = require('express');
    const static = require('express-static');
    //1.创建服务
    var server = express();
    
    // 3.处理请求
      // req,res与原生的是有区别的!!
        // 保留了原生的功能,增强了原有的功能(send)
          // 原生:
            // res.write();   类型有局限性
            // res.end();
          // 添加的:
            // res.send();    类似于write,但可以接收json
    server.use('/a.html',function(req,res){
      res.send('abc');  //类似于res.write()
      res.end();
    });
    server.use('/b.html',function(req,res){
      res.send('123');
      res.end();
    });
    
    //get()接收get请求、post接收post请求、use接收所有请求
    // server.get('/',function(req,res){ // console.log("有GET"); // }); // server.post('/',function(req,res){ // console.log("有POST"); // }); server.use('/',function(req,res){ console.log("USE了"); }); // 2.监听 server.listen(8081);

    //配置打开文件的路径,设置静态文件目录
    server.use(static('./section09/www'));
  • 相关阅读:
    [背包]JZOJ 3232 【佛山市选2013】排列
    内核空间、用户空间、虚拟地址
    进程与线程的概念
    Python中字符串颜色
    socket编程
    模块与包
    常用模块
    面向对象进阶
    面向对象编程
    函数式编程
  • 原文地址:https://www.cnblogs.com/LChenglong/p/11775987.html
Copyright © 2011-2022 走看看