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')
                })`
  • 相关阅读:
    linux网桥浅析
    linux slub分配器浅析
    vs2015 C# WinForm 使用皮肤 美化窗体
    枚举可以直接赋值给int
    LINK : fatal error LNK1000: Internal error during IncrBuildImage
    map映射类
    map
    time
    int to string
    eclipse
  • 原文地址:https://www.cnblogs.com/xiaoxiaodevlog/p/10704207.html
Copyright © 2011-2022 走看看