{"id":1139,"date":"2025-02-15T03:01:54","date_gmt":"2025-02-15T03:01:54","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=1139"},"modified":"2025-04-18T09:45:55","modified_gmt":"2025-04-18T09:45:55","slug":"nodejs3","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2025\/02\/15\/nodejs3\/","title":{"rendered":"nodejs3 &#8211; HTML, EJS \ud30c\uc77c \ubd88\ub7ec\uc624\uae30 \/ Importing HTML,EJS"},"content":{"rendered":"\n<p>package-lock.json\ud30c\uc77c\uc740 \uc790\ub3d9\uc0dd\uc131\ub418\ub294 \ud30c\uc77c\uc774\ub77c\uc11c \ub530\ub85c \uc62c\ub9ac\uc9c0 \uc54a\uaca0\uc2b5\ub2c8\ub2e4.<br>The package-lock.json file is an automatically generated file, so I will not upload it separately.<\/p>\n\n\n\n<p>server.js<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*---------------------------------------------------------------------------\n\n- NODEJS-3 : router\n- 2025.02.\n\n---------------------------------------------------------------------------*\/\n\nconst path = require('path'); \/\/ npm install path\nconst express = require('express'); \/\/ npm install express\nconst app = express();\nconst port = 3000; \n\n\/*---------------------------------------------------------------------------\n  start route\n---------------------------------------------------------------------------*\/\n\n\/\/ print: res.send('Hello, World!');\n\/\/ file: res.sendFile(path.join(__dirname, \"\/\", \"index1.html\"));\n\napp.get('\/', (req, res) =&gt; {\n  \/\/res.send('Hello, World!');\n  res.sendFile(path.join(__dirname, \"\/\", \"index1.html\"));\n\n  console.log(\"log:index1.html\");\n  console.log(`log: filename : ${__filename}`); \/\/ server.js\n  console.log(`log: path:${__dirname}`);\n});\n\n\/*---------------------------------------------------------------------------\n  Start Server\n---------------------------------------------------------------------------*\/\n\n\/\/ Start the server\napp.listen(port, () =&gt; {\n  console.log(`Server listening at http:\/\/localhost:${port}`);\n});\n\n<\/code><\/pre>\n\n\n\n<p>server2.js<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*---------------------------------------------------------------------------\n\n- NODEJS-3 : router2\n- 2025.02.\n\n---------------------------------------------------------------------------*\/\n\n\/\/ module : https:\/\/www.npmjs.com\nconst ejs = require('ejs');         \/\/ https:\/\/ejs.co\nconst path = require('path');       \/\/ https:\/\/nodejs.org\/docs\/latest\/api\/path.html\nconst express = require('express'); \/\/ https:\/\/expressjs.com\/\n\nconst app = express();\nconst port = 3000; \n\n\/\/ ejs\napp.set('view engine','ejs');\napp.set('views','.\/public');\n\n\n\/*---------------------------------------------------------------------------\n  Start route\n---------------------------------------------------------------------------*\/\n\n\/\/ print: res.send('Hello, World!');\n\/\/ file: res.sendFile(path.join(__dirname, \"\/\", \"index1.html\"));\n\/\/ ejs: res.render('view1')\n\napp.get('\/', (req, res) =&gt; {\n  \/\/res.send('Hello, World!');\n  res.sendFile(path.join(__dirname, \"\/\", \"index1.html\"));\n\n  console.log(\"log:index1.html\");\n  console.log(`log: filename : ${__filename}`); \/\/ server.js\n  console.log(`log: path:${__dirname}`); \/\/ directory path\n});\n\napp.get('\/view1', (req, res) =&gt; {\n  res.render('view1'); \/\/ ejs file\n});\n\n\n\/*---------------------------------------------------------------------------\n  Start Server\n---------------------------------------------------------------------------*\/\n\n\/\/ Start the server\napp.listen(port, () =&gt; {\n  console.log(`Server listening at http:\/\/localhost:${port}`);\n});\n\n<\/code><\/pre>\n\n\n\n<p>package.json<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"name\": \"nodejs3-1\",\n  \"version\": \"1.0.0\",\n  \"main\": \"server.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\",\n    \"start\": \"node server.js\"\n  },\n  \"author\": \"\",\n  \"license\": \"ISC\",\n  \"description\": \"\",\n  \"dependencies\": {\n    \"ejs\": \"^3.1.10\",\n    \"express\": \"^4.21.2\",\n    \"path\": \"^0.12.7\"\n  }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>package-lock.json\ud30c\uc77c\uc740 \uc790\ub3d9\uc0dd\uc131\ub418\ub294 \ud30c\uc77c\uc774\ub77c\uc11c \ub530\ub85c \uc62c\ub9ac\uc9c0 \uc54a\uaca0\uc2b5\ub2c8\ub2e4.The package-lock.json file is an automatically generated file, so I will not upload it separately. server.js server2.js package.json<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,1],"tags":[],"class_list":["post-1139","post","type-post","status-publish","format-standard","hentry","category-nodejs","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1139","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=1139"}],"version-history":[{"count":3,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1139\/revisions"}],"predecessor-version":[{"id":1158,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1139\/revisions\/1158"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=1139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=1139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=1139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}