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')
                })`
  • 相关阅读:
    BoundsChecker下载
    大型系统内部资源定位的途径
    架构的焦点
    为什么日志只应该有三个级别
    回收站引发ORACLE查询表空间使用缓慢
    题目记录
    广搜入门 待改进的广搜
    归并排序的使用
    大数数组中滚动数组的应用
    多重背包问题
  • 原文地址:https://www.cnblogs.com/xiaoxiaodevlog/p/10704207.html
Copyright © 2011-2022 走看看