@7util/log-express 中文文档教程

发布于 3年前 浏览 23 项目主页 更新于 3年前

logExpress :steam_locomotive:

Middleware logging calls for Express 4.x

$ npm install @7util/log-express

  • has timestamp,
  • method name,
  • url,
  • status code,
  • time it took for the server to respond in ms
  • includes TypeScript definitions

Example

app.js

import { logExpress } from '@7util/log-express';

const express = require('express')
const app = express()
const port = 3000

// enables call logging 
app.use(logExpress)

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})

// Start the server
// Open your browser navigate to http://localhost:3000/

// output
[2021-04-20 08:07:44] GET: / 200 7ms
[2021-04-20 08:07:45] GET: /favicon.ico 404 1ms

// refresh the page
// output
[2021-04-20 08:08:05] GET: / 304 2ms

Happy coding! <:beer:/>

logExpress :steam_locomotive:

Middleware logging calls for Express 4.x

$ npm install @7util/log-express

  • has timestamp,
  • method name,
  • url,
  • status code,
  • time it took for the server to respond in ms
  • includes TypeScript definitions

Example

app.js

import { logExpress } from '@7util/log-express';

const express = require('express')
const app = express()
const port = 3000

// enables call logging 
app.use(logExpress)

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})

// Start the server
// Open your browser navigate to http://localhost:3000/

// output
[2021-04-20 08:07:44] GET: / 200 7ms
[2021-04-20 08:07:45] GET: /favicon.ico 404 1ms

// refresh the page
// output
[2021-04-20 08:08:05] GET: / 304 2ms

Happy coding! <:beer:/>

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文