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')
                })`
  • 相关阅读:
    Volume 6. Mathematical Concepts and Methods
    git帮助网址
    ubuntu 下安装wine
    ubuntu 通过ppa源安装mysql5.6
    ubuntu qq安装
    ubuntu14.04 fcitx安装
    language support图标消失
    ubuntu root用户登陆
    ubuntu 安装codeblocks13.12
    ubuntu tomcat自启动
  • 原文地址:https://www.cnblogs.com/xiaoxiaodevlog/p/10704207.html
Copyright © 2011-2022 走看看