mirror of
https://github.com/typicode/json-server.git
synced 2025-07-31 22:25:05 +08:00
exit on help message and add logs
This commit is contained in:
@ -48,6 +48,7 @@ Options:
|
|||||||
-s, --static <dir> Static files directory (multiple allowed)
|
-s, --static <dir> Static files directory (multiple allowed)
|
||||||
--help Show this message
|
--help Show this message
|
||||||
`)
|
`)
|
||||||
|
process.exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (values.version) {
|
if (values.version) {
|
||||||
@ -63,12 +64,6 @@ const file = positionals[0] ?? ''
|
|||||||
const port = parseInt(values.port ?? process.env['PORT'] ?? '3000')
|
const port = parseInt(values.port ?? process.env['PORT'] ?? '3000')
|
||||||
const host = values.host ?? process.env['HOST'] ?? 'localhost'
|
const host = values.host ?? process.env['HOST'] ?? 'localhost'
|
||||||
|
|
||||||
// Check file
|
|
||||||
if (file === '') {
|
|
||||||
console.log('No file specified')
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!existsSync(file)) {
|
if (!existsSync(file)) {
|
||||||
console.log(`File ${file} not found`)
|
console.log(`File ${file} not found`)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
@ -125,5 +120,6 @@ if (process.env['NODE_ENV'] !== 'production') {
|
|||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Started on :${port}`)
|
console.log(`Started on :${port}`)
|
||||||
|
console.log(`Watching ${file}...`)
|
||||||
console.log(routes(db).join('\n'))
|
console.log(routes(db).join('\n'))
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user