Skip to content

Instantly share code, notes, and snippets.

@suguru03
Created September 16, 2016 16:24
Show Gist options
  • Save suguru03/3eb7d94602a109c07321605bd481f33c to your computer and use it in GitHub Desktop.
Save suguru03/3eb7d94602a109c07321605bd481f33c to your computer and use it in GitHub Desktop.
```npm i express body-parser`
'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