Web Programming/Node.js
-
mysql에서 pool query 후 release 하기2018.12.04
-
Express.js IP 구하기2018.07.03
-
간단한 express서버 만들기2017.08.15
mysql에서 pool query 후 release 하기
2018.12.04 12:25
mysql 모듈에서 pool을 사용한 다음 release를 하지 않아도 된다.
이슈(https://github.com/mysqljs/mysql/issues/1202)를 참고하면,
yes.pool.query()
is shortcut forpool.getConnection()
+connection.query()
+connection.release()
- see https://github.com/felixge/node-mysql/blob/master/lib/Pool.js#L194-L207
아래와 같이 답변이 있다.
pool.query()는 getConnection()과 query, 커넥션 release가 포함되어있다는 내용이다.
'Web Programming > Node.js' 카테고리의 다른 글
mysql에서 pool query 후 release 하기 (0) | 2018.12.04 |
---|---|
Express.js IP 구하기 (0) | 2018.07.03 |
간단한 express서버 만들기 (0) | 2017.08.15 |
Express.js IP 구하기
2018.07.03 14:04
Express.js에서 접속자의 IP를 반환하는 함수는 아래와 같다.
const getIp = req => (req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress);
Express를 사용할 때 아래코드도 덤으로 넣어주어야 한다. "app.set('trust proxy', true);
'Web Programming > Node.js' 카테고리의 다른 글
mysql에서 pool query 후 release 하기 (0) | 2018.12.04 |
---|---|
Express.js IP 구하기 (0) | 2018.07.03 |
간단한 express서버 만들기 (0) | 2017.08.15 |
간단한 express서버 만들기
2017.08.15 23:46
1 2 3 4 5 6 7 8 9 10 11 12 13 | const express = require('express'); //express const path = require('path'); const app = express(); app.use(express.static('public')); app.get('/',(req,res)=>{ //on GET (route : /) res.sendFile('./main.html'); }); app.get('/a',(req,res)=>{ //on GET (route : /a) res.sendFile('./a.html'); }); require('http').createServer(app).listen(7200,()=> { console.log("Server Start!"); }); //Create http server : port(7200) | cs |
1번부터 2번까지는 모듈을 로드하는것이고
5번줄 부터 10번째 줄까지는 라우팅을 하는 부분입니다. GET에서 각각 / 과 /a를 받으면 main.html과 a.html을 보냅니다.
11번줄은 http모듈의 createServer함수로 7200포트에서 실행되며, 실행시 console.log의 내용을 출력합니다.
참고 : const와 ()=>문법은 Node.js 6.x부터 지원됩니다.
'Web Programming > Node.js' 카테고리의 다른 글
mysql에서 pool query 후 release 하기 (0) | 2018.12.04 |
---|---|
Express.js IP 구하기 (0) | 2018.07.03 |
간단한 express서버 만들기 (0) | 2017.08.15 |