Skip to content

Latest commit

 

History

History
21 lines (16 loc) · 468 Bytes

open 模块.md

File metadata and controls

21 lines (16 loc) · 468 Bytes

open 模块

启动 express 服务时,我们使用 open 包将在默认浏览器打开到 localhost

const app = require('express')()
const open = require('open')

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

const port = 3000
const host = 'localhost'

app.listen(port, host, (err) => {
  if (err) return
  open(`http://${host}:${port}`)
  console.log(`Listening at http://${host}:${port}`)
})