zoukankan      html  css  js  c++  java
  • NodeJS基础(二)

    一、动态获取文件路径

    var fs = require('fs')
    var path = require('path')
    
    // 一般在开发命令行工具的时候,这个设计是必须有用的一个特性
    // npm
    // webpack
    // __dirname 和 __filename 这俩就是专门用来动态获取当前文件以及文件所属目录的绝对路径
    fs.readFile(path.join(__dirname, './00-文件路径.js'), function (err, data) {
        if (err) {
            throw err
        }
        console.log(data.toString())
    })

    二、中间件

    应用程序级别中间件
         + 万能匹配(不关心任何请求路径和请求方法)
        + `app.use(function (req, res, next)     {
              console.log('haha')
              next()
            })`
        + 只要是以'/xxx/'开头的:
        + `app.use('/a', function (req, res, next) {
                  console.log('/a')
                })`
    
     - 路由级别中间件
         + get:
         + `app.get('/a', function (req, res, next) {
                  console.log('/a')
                })`
        + post:
         + `app.post('/a', function (req, res, next) {
                  console.log('/a')
                })`
        + put:
         + `app.put('/a', function (req, res, next) {
                  console.log('/a')
                })`
    
        + delete+ `app.delete('/a', function (req, res, next) {
                  console.log('/a')
                })`
  • 相关阅读:
    cadence中画焊盘注意事项
    频率带宽解释
    一种RC滤波电路的验证
    24L01-2.4G无线传输模块调节记录
    51中xdata,idata,data,pdata的区别
    调试24L01经验总结
    将scl分频
    I2C详细介绍
    汽车电源系统概述
    PCB命名规则-allegro
  • 原文地址:https://www.cnblogs.com/xiaoxiaodevlog/p/10704207.html
Copyright © 2011-2022 走看看