04-07 06:55
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

[WebApp / Express] ini Parser 본문

Programming/Web App

[WebApp / Express] ini Parser

cinema4dr12 2015. 11. 12. 00:04

Express App 의 환경설정을 위한 Node Package Module의 하나인 ini Parser에 대하여 간단하게 알아보자.


다운로드

다른 Node Package Module과 마찬가지로 npm 명령어를 이용하여 다운로드 할 수 있다.

$ npm install iniparser



ini 파일 정의

Text editor를 이용하여 "config.ini" 파일을 다음과 같이 정의한다.

[config.ini]

title = My Express App
port = 9000
message = Hello World!



app.js 수정

app.js 파일을 다음과 같이 수정한다.


[app.js]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
var config = iniparser.parseSync('./config.ini');
...
// ini config
app.get('/', function(req, res, next) {
  res.render('index', {
    title:config2.title,
    message:config2.message
  });
});
...
var server = app.listen(app.get('port'), function() {
  console.log('Express server listening on port ' + server.address().port);
  console.log('App started on port : ' + config.port);
});
...



Result




Comments