Created
September 16, 2016 16:24
-
-
Save suguru03/3eb7d94602a109c07321605bd481f33c to your computer and use it in GitHub Desktop.
```npm i express body-parser`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const path = require('path'); | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const app = express(); | |
const port = process.env.PORT || 8000; | |
app.use(bodyParser.json()); | |
app.use(express.static(path.resolve(__dirname, 'public'))); | |
app.route('/test') | |
.get((req, res) => { | |
console.log('**** get ****' , req.body); | |
res.send('get'); | |
}) | |
.post((req, res) => { | |
console.log('**** post ****' , req.body); | |
res.send('post'); | |
}) | |
app.listen(port); | |
console.info(`server start ${port}`); | |
/** | |
* curl http://127.0.0.1:8000/test | |
* curl -X POST http://127.0.0.1:8000/test | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment