Hello World with express-decorators
{
"scripts": {
"start": "babel-node hello-world.js",
},
"dependencies": {
"babel-cli": "^6.18.0",
"babel-plugin-transform-async-to-generator": "^6.16.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.18.0",
"express": "^4.14.0",
"express-decorators": "^0.5.0"
}
}
import express from 'express'
import {controller, get} from 'express-decorators'
// define app
const app = express()
// define a controller class
@controller('/hello')
class HelloController {
@get('/:target')
async sayHelloAction(request, response) {
response.send(`hello ${request.params.target||'world'}!!`)
}
}
let hello = new HelloController()
hello.register(app)
//boot
app.listen(3000, () => console.log('App running on 3000'))
{
"presets": ["es2015"],
"plugins": [
"transform-decorators-legacy",
"transform-async-to-generator"
]
}