모듈 작성하기
파일명 : myfirstmodule.js
exports.myDateTime = function () {
return Date();
}
exports 키워드를 사용함.
모듈 적용하기
파일명 : main.js
var http = require('http');
var dt = require('./myfirstmodule');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write("The date adn time are currently: " + dt.myDateTime());
res.end();
}).listen(8080);
반응형
'프로그래밍 > Node.js' 카테고리의 다른 글
| Node.js > devDependencies 과 dependencies 차이점 (0) | 2024.11.17 |
|---|---|
| Node.js에 대해서 (0) | 2024.07.06 |
| PM2란? (0) | 2022.09.05 |
| Node.js 내컴퓨터에 설치하기 (macOS) (0) | 2022.09.03 |
| NPM 이란? (0) | 2022.08.07 |