NPM moment module

nodejs를 설치 하고 npm명령어를 통하여 패키지를 설치 하면 사용 할 수 있습니다.
기본 적인 패키지 설치 명령어는 아래와 같습니다.
You can use it by installing nodejs and installing the package through the npm command.
The basic package installation command is as follows.

# npm install moment

moment모듈의 용도는 JavaScript로 날짜와 시간을 구문 분석, 검증, 조작 및 표시를 하기 위해서 사용합니다.
(memonet웹사이트 참조)
moment 모듈의 기본적인 사용방법은 https://momentjs.com/ 첫페이지에서 확인 할 수 있다.
The purpose of the moment module is to parse, verify, manipulate, and display dates and times in JavaScript.
(Refer to memonet website)
Basic instructions for using the moment module can be found on the first page of https://momentjs.com

아래는 moment를 사용하는 sever.js 예제 코드 입니다.
Below is sever.js example code using moment.

const http = require('http');
const moment = require('moment');

const server = http.createServer((req, res) => {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('CommonJS:Hello World!\n');
  });

// moment package 
// usage : https://momentjs.com/
const mtime = moment().format('MMMM Do YYYY, h:mm:ss a');
const mtimes = moment().format('LT');
console.log(mtime);
console.log(mtimes);


// Start the server
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
  console.log(`CommonJS:Server is running on port ${PORT}`);
});

Leave a Reply

Your email address will not be published. Required fields are marked *