반응형
Express설치는 매우 간단하기 때문에, 아래 링크를 참조해서 잘 깔면된다.
https://www.tutorialspoint.com/nodejs/nodejs_express_framework.htm
Express가 설치되었다는 가정하에, 아래 코드 몇 줄이면 application/json 으로 통신이 가능한 웹 서버를 띄울 수가 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | var express = require( 'express' ); var app = express(); var bodyParser = require( 'body-parser' ); app.use(bodyParser.json()); // 이 부분이 Json Protocol을 지원하겠다는 의미 // POST API 등록 app.post( '/test_json_api' , function (req, res) { req.accepts( 'application/json' ); jsonBody = req.body; // json parsing console.log(jsonBody); }); // 8081 포트로 서버를 띄운다. app.listen(8081, function () { console.log( 'server listening on port %s.' , 8081); }); |
반응형
'개발 > Node.js' 카테고리의 다른 글
[Sequelize] timezone 세팅 (0) | 2016.12.26 |
---|---|
[Node.js] sh: 1: Permission denied 해결 (0) | 2016.12.20 |
[Express] static contents 접근 및 HTML rendering (0) | 2016.12.19 |
[Node.js] 커스텀 모듈 만들어서 import 하기 (0) | 2016.12.19 |