0.0.1 • Published 7 years ago
trek v0.0.1
Features
Elegant. Use
async
andawait
for asynchronous programsFast. High performance middleware and router
Modern. ES6+, only for Node.js v8+
Flexible. Modular and extensible
Amiable. Similar to Express.js and Koa.js
Installation
$ npm install trek --save
Examples
Hello Trek
The lightweight app uses with Engine. Likes Koa.
import { Engine as Trek } from 'trek'
const app = new Trek()
app.use(async ({ res }, next) => {
const start = new Date()
await next()
const ms = new Date() - start
console.log(`${ms}ms`)
res.end('Hello Trek!')
})
app.run(3000)
Star Trek
The richer app, customize and expand your app.
import Trek, { Router } from 'trek'
(async () => {
// router
const router = new Router()
router.get('/', async ({ res }) => {
res.send(200, 'Hello, Trek!')
})
router.get('/startrek', async ({ res }) => {
res.send(200, new Buffer('Hello, Star Trek!'))
})
router.post('/', async ({ res }) => {
res.send(200, {
status: 'ok',
message: 'success'
})
})
// app
const app = new Trek()
// customize paths of app
app.paths.set('app', { single: true })
app.paths.set('app/plugins', { glob: 'app/plugins/index.js', single: true })
app.paths.set('app/controllers', { glob: 'app/controllers/*.js' })
// autoload plugins
await app.bootUp()
// middleware
app.use(async ({ req, res }, next) => {
const start = new Date()
await next()
const ms = new Date() - start
console.log(`${ms}ms`)
})
// work with router
app.use(async ({ req, res }, next) => {
const route = router.find(req.method, req.path)
if (route) {
const [handler] = route
if (handler !== undefined) {
return await handler({ req, res })
}
}
await next()
})
app.use(async ({ res }) => {
res.status = 404
res.end()
})
// start
await app.run(3000)
})().catch(console.error)
0.0.1
7 years ago
1.0.0
8 years ago
0.2.3
9 years ago
0.2.2
9 years ago
0.2.1
9 years ago
0.2.0
9 years ago
0.1.11
9 years ago
0.1.10
9 years ago
0.1.9
9 years ago
0.1.8
9 years ago
0.1.7
9 years ago
0.1.6
9 years ago
0.1.5
9 years ago
0.1.4
9 years ago
0.1.3
9 years ago
0.1.2
9 years ago
0.1.1
9 years ago
0.1.0
9 years ago
0.0.12-dev
9 years ago
0.0.11-dev
9 years ago
0.0.10-dev
9 years ago
0.0.9-dev
9 years ago
0.0.8-dev
9 years ago
0.0.7-dev
9 years ago
0.0.6-dev
9 years ago
0.0.5-dev
9 years ago
0.0.4-dev
9 years ago
0.0.3-dev
9 years ago
0.0.2-dev
9 years ago
0.0.1-dev
9 years ago
0.0.0-dev
9 years ago
0.0.0
10 years ago