Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/will123195/express-pages

Automatic routing for express
https://github.com/will123195/express-pages

Last synced: 10 days ago
JSON representation

Automatic routing for express

Awesome Lists containing this project

README

        

# express-pages

Automatic routing for express

## Install

```
npm install express
npm install express-pages
```

## Usage

#### index.js
```js
var express = require('express')
var pages = require('express-pages')
var app = express()

app.set('port', (process.env.PORT || 5000))

app.use('/v1', pages({
dir: './api',
ext: '.js',
homepage: '/home',
helpers: {
beep: function () {
return 'boop'
}
}
})

app.listen(app.get('port'), function() {
console.log([
'Running: http://localhost:' + app.get('port'),
'NODE_ENV: ' + process.env.NODE_ENV,
].join('\n'))
})
```

#### ./api/beep.js
```js
//
// /v1/beep
//
module.exports = function () {
this.send({
beep: this.beep()
})
}
```