{"id":399,"date":"2024-04-17T07:10:29","date_gmt":"2024-04-17T07:10:29","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=399"},"modified":"2026-07-12T10:30:42","modified_gmt":"2026-07-12T01:30:42","slug":"npm-moment-module","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2024\/04\/17\/npm-moment-module\/","title":{"rendered":"[nodejs]NPM moment module"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb moment\uc744 \ubaa8\ub4c8\uc744 \uc124\uce58\ud558\uba74 npm \ubaa8\ub4c8 \uc124\uce58\ubc29\ubc95\uc5d0 \ub300\ud574\uc11c \ubc30\uc6b8 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>By installing the <code>moment<\/code> module, you can learn how to install npm modules.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb moment\ubaa8\ub4c8\uc740 \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8\ub85c \uc2dc\uac04\uc5d0 \ub300\ud55c \ub2e4\uc591\ud55c \ud615\uc2dd\uc744 \ud45c\ud604\ud560 \uc218 \uc788\uac8c \ud574\uc90d\ub2c8\ub2e4.<br>The moment module allows you to represent time in various formats using JavaScript.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb nodejs\ub97c \uc124\uce58 \ud558\uace0 npm\uba85\ub839\uc5b4\ub97c \ud1b5\ud558\uc5ec \ud328\ud0a4\uc9c0\ub97c \uc124\uce58 \ud558\uba74 \uc0ac\uc6a9 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>\uae30\ubcf8 \uc801\uc778 \ud328\ud0a4\uc9c0 \uc124\uce58 \uba85\ub839\uc5b4\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<br>You can use it by installing nodejs and installing the package through the npm command.<br>The basic package installation command is as follows.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># npm install moment<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb moment\ubaa8\ub4c8\uc758 \uc6a9\ub3c4\ub294 JavaScript\ub85c \ub0a0\uc9dc\uc640 \uc2dc\uac04\uc744 \uad6c\ubb38 \ubd84\uc11d, \uac80\uc99d, \uc870\uc791 \ubc0f \ud45c\uc2dc\ub97c \ud558\uae30 \uc704\ud574\uc11c \uc0ac\uc6a9\ud569\ub2c8\ub2e4.<br>(memonet\uc6f9\uc0ac\uc774\ud2b8 \ucc38\uc870)<br>moment \ubaa8\ub4c8\uc758 \uae30\ubcf8\uc801\uc778 \uc0ac\uc6a9\ubc29\ubc95\uc740 <a href=\"https:\/\/momentjs.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/momentjs.com\/<\/a> \uccab\ud398\uc774\uc9c0\uc5d0\uc11c \ud655\uc778 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<p><br>The purpose of the moment module is to parse, verify, manipulate, and display dates and times in JavaScript.<br>(Refer to memonet website)<br>Basic instructions for using the moment module can be found on the first page of <a href=\"https:\/\/momentjs.com\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/momentjs.com<\/a><br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"891\" height=\"929\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/04\/momentjs-1.png\" alt=\"\" class=\"wp-image-408\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/04\/momentjs-1.png 891w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/04\/momentjs-1-288x300.png 288w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/04\/momentjs-1-768x801.png 768w\" sizes=\"auto, (max-width: 891px) 100vw, 891px\" \/><\/figure>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uc544\ub798\ub294 moment\ub97c \uc0ac\uc6a9\ud558\ub294 sever.js \uc608\uc81c \ucf54\ub4dc \uc785\ub2c8\ub2e4.<br>Below is sever.js example code using moment.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const http = require('http');\nconst moment = require('moment');\n\nconst server = http.createServer((req, res) =&gt; {\n    res.writeHead(200, { 'Content-Type': 'text\/plain' });\n    res.end('CommonJS:Hello World!\\n');\n  });\n\n\/\/ moment package \n\/\/ usage : https:\/\/momentjs.com\/\nconst mtime = moment().format('MMMM Do YYYY, h:mm:ss a');\nconst mtimes = moment().format('LT');\nconsole.log(mtime);\nconsole.log(mtimes);\n\n\n\/\/ Start the server\nconst PORT = process.env.PORT || 3000;\nserver.listen(PORT, () =&gt; {\n  console.log(`CommonJS:Server is running on port ${PORT}`);\n});\n<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb\uc2e4\ud589 \/ Run<\/p>\n\n\n\n<p>\u2714\ufe0f \ud130\ubbf8\ub110 \/ Terminal<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>moment % node server.js\nJuly 10th 2025, 02:02:12 am\n02:02 AM\nCommonJS:Server is running on port 3000<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ube0c\ub77c\uc6b0\uc800 \/ Browser<\/p>\n\n\n\n<p>&#8212; \ud130\ubbf8\ub110\uc5d0\uc11c \uc11c\ubc84 \uc2e4\ud589 \ud6c4 \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c \ud655\uc778 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>You can check it in your browser after running the server in the terminal.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"820\" height=\"386\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/04\/momentbr-jpg.jpg\" alt=\"\" class=\"wp-image-6316\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/04\/momentbr-jpg.jpg 820w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/04\/momentbr-jpg-300x141.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/04\/momentbr-jpg-768x362.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/04\/momentbr-jpg-400x188.jpg 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/04\/momentbr-jpg-800x377.jpg 800w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><figcaption class=\"wp-element-caption\">Browser<\/figcaption><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ucf54\ub4dc \uc124\uba85 \/ Code Explanation<\/p>\n\n\n\n<p>\u2714\ufe0f package.json<\/p>\n\n\n\n<p>&#8212; dependencies\ud56d\ubaa9\uc5d0 moment\uac00 \uc788\uc5b4\uc57c\ud569\ub2c8\ub2e4.<br><code>moment<\/code> must be included in the <code>dependencies<\/code> section.<\/p>\n\n\n\n<p>&#8212; npm install moment\ub97c \uc2e4\ud589\ud558\uba74 moment\ud56d\ubaa9\uc774 \uc790\ub3d9\ucd94\uac00\ub429\ub2c8\ub2e4.<br>Running <code>npm install moment<\/code> automatically adds the <code>moment<\/code> entry.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n  \"name\": \"moment\",\n  \"version\": \"1.0.0\",\n  \"description\": \"moment\",\n  \"license\": \"ISC\",\n  \"author\": \"\",\n  \"type\": \"commonjs\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"\n  },\n  \"dependencies\": {\n    <strong>\"moment\": \"^2.30.1\"<\/strong>\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f server.js<\/p>\n\n\n\n<p>&#8212; moment \ubaa8\ub4c8\uc744 \ucd94\uac00\ud558\ub294 \ubd80\ubd84\uc785\ub2c8\ub2e4.<br>This is the part where the <code>moment<\/code> module is added.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const moment = require('moment');<\/code><\/pre>\n\n\n\n<p>&#8212; \uc5ec\ub7ec\uac00\uc9c0 \ud615\uc2dd\uc758 \uc2dc\uac04\uc740 \ud130\ubbf8\ub110\uc5d0 \ucd9c\ub825\ud569\ub2c8\ub2e4.<br>It outputs the time in various formats to the terminal.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const mtime = moment().format('MMMM Do YYYY, h:mm:ss a');\nconst mtimes = moment().format('LT');\nconsole.log(mtime);\nconsole.log(mtimes);<\/code><\/pre>\n\n\n\n<p>&#8212; \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c 3000\ubc88 \ud3ec\ud2b8\ub85c \uc2e4\ud589\ub420 http\uc11c\ubc84\ub97c \uad6c\uc131\ud558\ub294 \ubd80\ubd84\uc785\ub2c8\ub2e4.<br>This section configures the HTTP server to run on port 3000 in the browser.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const http = require('http');\n\n...\n\nconst server = http.createServer((req, res) => {\n    res.writeHead(200, { 'Content-Type': 'text\/plain' });\n    res.end('CommonJS:Hello World!\\n');\n  });\n\n...\n\n\/\/ Start the server\nconst PORT = process.env.PORT || 3000;\nserver.listen(PORT, () => {\n  console.log(`CommonJS:Server is running on port ${PORT}`);\n});<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb moment\uc744 \ubaa8\ub4c8\uc744 \uc124\uce58\ud558\uba74 npm \ubaa8\ub4c8 \uc124\uce58\ubc29\ubc95\uc5d0 \ub300\ud574\uc11c \ubc30\uc6b8 \uc218 \uc788\uc2b5\ub2c8\ub2e4.By installing the moment module, you can learn how to install npm modules. \ud83d\udc49\ud83c\udffb moment\ubaa8\ub4c8\uc740 \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8\ub85c \uc2dc\uac04\uc5d0 \ub300\ud55c \ub2e4\uc591\ud55c \ud615\uc2dd\uc744 \ud45c\ud604\ud560 \uc218 \uc788\uac8c \ud574\uc90d\ub2c8\ub2e4.The moment module allows you to represent time in various formats using JavaScript. \ud83d\udc49\ud83c\udffb nodejs\ub97c \uc124\uce58 \ud558\uace0 npm\uba85\ub839\uc5b4\ub97c \ud1b5\ud558\uc5ec \ud328\ud0a4\uc9c0\ub97c \uc124\uce58 \ud558\uba74 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-399","post","type-post","status-publish","format-standard","hentry","category-nodejs","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=399"}],"version-history":[{"count":36,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/399\/revisions"}],"predecessor-version":[{"id":6337,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/399\/revisions\/6337"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}