일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Statistics
- 빅 데이터
- 몽고디비
- 빅데이타
- MongoDB
- No SQL
- 주일설교
- 김양재 목사님
- 확률
- c++
- 딥러닝
- 김양재
- WebGL
- 빅데이터
- Machine Learning
- 빅 데이타
- Big Data
- R
- data science
- 김양재 목사
- Artificial Intelligence
- probability
- 통계
- 우리들교회
- nodeJS
- openCV
- node.js
- Deep learning
- 인공지능
- 데이터 과학
Archives
- Today
- Total
Scientific Computing & Data Science
[WebApp / Express] 간단한 Node Module 만들기 본문
이번 글에서는 NodeJS의 Express Framework에 대하여 간단한 Node Module을 작성하는 방법을 알아보도록 하자.
방법 1 - 각 Method를 개별적으로 Export
{EXPRESS_APP_PATH}/routes/mymod.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | var name = exports.name = 'GChoi' ; var secret = 'gchoi' ; exports.lower = function(input) { return input.toLowerCase(); }; exports.upper = function(input) { return input.toUpperCase(); }; exports.get_name = function() { return name; }; exports.get_secret = function() { return secret; }; |
{EXPRESS_APP_PATH}/routes/test.js
1 2 3 4 5 6 7 | var mymod = require( './mymod.js' ); console. log (mymod.name); console. log (mymod.lower( "MacBook" )); console. log (mymod.upper( "Apple" )); console. log (mymod.get_name()); console. log (mymod.get_secret()); |
{EXPRESS_APP_PATH}/routes/app.js
1 2 3 | ... var test = require( './routes/test' ); ... |
Part 2 - JSON Format으로 Export
{EXPRESS_APP_PATH}/routes/mymod2.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | var secret = 'MacBook' ; module.exports = { name: 'iPhone' , lower: function(input) { return input.toLowerCase(); }, upper: function(input) { return input.toUpperCase(); }, get_name: function() { return this .name; }, get_secret: function() { return secret; } }; |
{EXPRESS_APP_PATH}/routes/test.js
1 2 3 4 5 6 7 | var mymod2 = require( './mymod2.js' ); console. log (mymod2.name); console. log (mymod2.lower( "MacBook" )); console. log (mymod2.upper( "Apple" )); console. log (mymod2.get_name()); console. log (mymod2.get_secret()); |
{EXPRESS_APP_PATH}/routes/app.js
1 2 3 | ... var test = require( './routes/test' ); ... |
'Programming > Web App' 카테고리의 다른 글
[Web App / Express] Development/Production Mode (0) | 2015.11.07 |
---|---|
[Web App / Express] Logger 사용법 (0) | 2015.11.02 |
[WebApp / AWS] Mac에서 AWS Windows Server 원격제어하기 (0) | 2015.09.29 |
[WebApp/AWS] Filezilla FTP로 Amazon Web Serivce EC2 접속하기 (1) | 2015.08.06 |
[WebApp/AWS] Amazon Web Serivce EC2를 이용하여 NodeJS 웹 서버 구축하기 (24) | 2015.06.20 |