koa-viewer
v0.0.5
Published
Directory and file viewer for koa 2
Downloads
7
Readme
koa-viewer
Directory and file viewer for koa 2
Usage
Scene 1:
import Koa from 'koa'
import viewer from 'koa-viewer'
const app = new Koa()
app.use(viewer())
app.listen(3000, function() {
console.log('Server listening on http://localhost:3000')
})
Scene 2:
import Koa from 'koa'
import viewer from 'koa-viewer'
const app = new Koa()
app.use(async(ctx, next) => {
ctx.body = await viewer(process.cwd(), {
flat: true,
nodir: true,
dot: false
})(ctx)
await next()
})
app.listen(3000, function() {
console.log('Server listening on http://localhost:3000')
})
**Scene 3: **
const Koa = require('koa')
const viewer = require('koa-viewer').default
const app = new Koa()
app.use(viewer())
app.listen(3000, function () {
console.log('Server listening on http://localhost:3000')
})
Demo
API
viewer([root], [options])
- root: String, root directory, default:
process.cwd()
options:
flat
: Boolean, default isfalse
, whentrue
, list files in the flat way.- node-glob: support
glob
options
Development
git clone https://github.com/neikvon/koa-viewer.git
npm run watch