{"id":1142,"date":"2025-02-21T02:08:34","date_gmt":"2025-02-21T02:08:34","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=1142"},"modified":"2026-07-11T09:45:08","modified_gmt":"2026-07-11T00:45:08","slug":"nodejs4","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2025\/02\/21\/nodejs4\/","title":{"rendered":"nodejs4 &#8211; GET and POST Data Transmission Methods \/ GET,POST \ub370\uc774\ud130 \uc804\uc1a1\ubc29\uc2dd"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb GET,POST \ub370\uc774\ud130 \uc804\uc1a1\ubc29\uc2dd<br>GET,POST METHOD GET and POST Data Transmission Methods<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb nodejs\uc5d0\uc11c \ub370\uc774\ud130 \uc804\uc1a1\ubc29\uc2dd\uc744 \uc124\uba85\ud558\ub294 \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8 \ucf54\ub4dc\uc785\ub2c8\ub2e4.<br>This is JavaScript code that explains data transmission methods in Node.js.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb MacOS\uc5d0\uc11c \ud14c\uc2a4\ud2b8\ud588\uc9c0\ub9cc \ub300\ubd80\ubd84\uc758 OS\ud658\uacbd\uc5d0\uc11c \ub3d9\uc77c\ud558\uac8c \uc2e4\ud589\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>It was tested on macOS, but it can be run in the same way on most operating systems.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ud30c\uc77c \/ files<\/p>\n\n\n\n<p>\u2714\ufe0f Project Root <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>html\t\t\tpackage.json\t\tserver2.js\nnode_modules\t\tpublic\npackage-lock.json\tserver.js<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f html,public<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- html\nindex.html\n\n- public\nget1.ejs    post1.ejs.    view1.ejs<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ubaa8\ub4c8 \uc124\uce58 \/ Module Installation<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm install body-parser  \nnpm install ejs\nnpm install express\nnpm install path<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uc804\uccb4 \ucf54\ub4dc \/  Full Code<\/p>\n\n\n\n<p>\u2714\ufe0fpackage.json<\/p>\n\n\n\n<p>&#8212; \uc124\uce58\ub41c \ubaa8\ub4c8\uc815\ubcf4\uc785\ub2c8\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"dependencies\": {\n    \"body-parser\": \"^1.20.3\",\n    \"ejs\": \"^3.1.10\",\n    \"express\": \"^4.21.2\",\n    \"path\": \"^0.12.7\"\n  }\n}\n<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0fserver.js<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*---------------------------------------------------------------------------\n\n- NODEJS-4 : get method\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\/\/ static directory\n\/\/ app.use(express.static(path.join(__dirname, \"public\")));\n\n\/*---------------------------------------------------------------------------\n  Start route\n---------------------------------------------------------------------------*\/\n\napp.get('\/', (req, res) =&gt; {\n  \/\/res.send('Hello, World!');\n  res.sendFile(path.join(__dirname, \"\/html\", \"\/index.html\")); \/\/ html directory,index.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\napp.get('\/get1', (req, res) =&gt; {\n    const id = req.query.id;\n    const name = req.query.name;\n\n    console.log(`id: ${id}`)\n    console.log(`name : ${name}`)\n    res.render('get1',{fid: id,fname: name}); \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>\u2714\ufe0fserver2.js<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*---------------------------------------------------------------------------\n\n- NODEJS-4 : get,post method\n- 2025.02.\n\n---------------------------------------------------------------------------*\/\n\n\/\/ module : https:\/\/www.npmjs.com\nvar bodyParser = require('body-parser'); \/\/ POST,https:\/\/github.com\/expressjs\/body-parser#readme\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\/\/ static directory\n\/\/ app.use(express.static(path.join(__dirname, \"public\")));\n\n\/\/ post method\napp.use(express.urlencoded({ extended: true }));  \/\/ For form post method\napp.use(express.json()); \/\/ For parsing JSON data\n\n\/*---------------------------------------------------------------------------\n  Start route\n---------------------------------------------------------------------------*\/\n\napp.get('\/', (req, res) =&gt; {\n  \/\/res.send('Hello, World!');\n  res.sendFile(path.join(__dirname, \"\/html\", \"\/index.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\napp.get('\/get1', (req, res) =&gt; {\n    const id = req.query.id; \n    console.log(`id: ${id}`)\n    res.render('get1',{fid: id}); \/\/ ejs file\n});\n\n\/\/---------------------------------------------------------------\n\napp.get('\/form', (req, res) =&gt; {\n  res.send(`\n      &lt;form method=\"POST\" action=\"\/formProc\"&gt;\n          &lt;label for=\"name\"&gt;Name:&lt;\/label&gt;\n          &lt;input type=\"text\" id=\"name\" name=\"name\"&gt;&lt;br&gt;&lt;br&gt;\n\n          &lt;label for=\"email\"&gt;Email:&lt;\/label&gt;\n          &lt;input type=\"email\" id=\"email\" name=\"email\"&gt;&lt;br&gt;&lt;br&gt;\n          &lt;button type=\"submit\"&gt;Submit&lt;\/button&gt;\n      &lt;\/form&gt;\n  `);\n});\n\napp.post(\"\/formProc\", (req, res) =&gt; {\n    \n    const name = req.body.name;\n    const email = req.body.email;\n\n    console.log(`form name : ${name}`)\n    console.log(`form email : ${email}`)\n    res.render('post1',{fname: name,femail: email});\n});\n\n\/\/---------------------------------------------------------------\napp.get('\/formapi', (req, res) =&gt; {\n  res.send(`\n      &lt;form method=\"POST\" action=\"\/api\"&gt;\n          &lt;label for=\"api\"&gt;API&lt;\/label&gt;&lt;br&gt;&lt;br&gt;\n          &lt;label for=\"name\"&gt;Name:&lt;\/label&gt;\n          &lt;input type=\"text\" id=\"name\" name=\"name\"&gt;&lt;br&gt;&lt;br&gt;\n\n          &lt;label for=\"email\"&gt;Email:&lt;\/label&gt;\n          &lt;input type=\"email\" id=\"email\" name=\"email\"&gt;&lt;br&gt;&lt;br&gt;\n          &lt;button type=\"submit\"&gt;Submit&lt;\/button&gt;\n      &lt;\/form&gt;\n  `);\n});\n\n\napp.post('\/api', (req, res) =&gt; {\n  console.log(\"Received JSON data:\", req.body);\n\n  res.json({ message: \"Data received successfully!\", data: req.body }); \/\/ Send JSON response\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>\u2714\ufe0f \/html\/index.html<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;h3>index.html&lt;\/h3><\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \/public\/get1.ejs<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;h3&gt;get1.ejs&lt;\/h3&gt;&lt;br&gt;\n&lt;h3&gt;fid:&lt;%=fid%&gt;&lt;\/h3&gt;&lt;br&gt;\n&lt;h3&gt;fname:&lt;%=fname%&gt;&lt;\/h3&gt;<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \/public\/post1.ejs<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;h3&gt;post1.ejs&lt;\/h3&gt;&lt;br&gt;\n&lt;h3&gt;name : &lt;%=fname%&gt;&lt;\/h3&gt;&lt;br&gt;\n&lt;h3&gt;email : &lt;%=femail%&gt;&lt;\/h3&gt;\n<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \/public\/view1.ejs<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;h3&gt;view1.ejs&lt;\/h3&gt;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\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<p>&#8212; \ud130\ubbf8\ub110\uc744 \uc5f4\uace0 \uc544\ub798\ucc98\ub7fc server.js\ub098 server2.js\ub97c \uc2e4\ud589\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>You can open a terminal and run <code>server.js<\/code> or <code>server2.js<\/code> as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># server.js\uc2e4\ud589\n# Run server.js\nnode server.js\n\n# server2.js\uc2e4\ud589\n# Run server2.js\nnode server.js<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ube0c\ub77c\uc6b0\uc800 \/ Browser<\/p>\n\n\n\n<p>&#8212; \uc11c\ubc84 \uc2e4\ud589\ud6c4 \ube0c\ub77c\uc6b0\uc800\ub97c \uc5f4\uace0 \ub2e4\uc74c \ucc98\ub7fc \uc8fc\uc18c\ub97c \uc785\ub825\ud569\ub2c8\ub2e4.<br>After starting the server, open your browser and enter the address as follows.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:3000<\/code><\/pre>\n\n\n\n<p>&#8212; \uc8fc\uc18c \ub4a4\uc5d0 \ub77c\uc6b0\ud130\ub97c \ubd99\uc5ec\uc11c \ud14c\uc2a4\ud2b8 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>You can test it by appending &#8220;\/router&#8221; to the address.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"http:\/\/localhost:3000\">http:\/\/localhost:3000<\/a>\/view1<\/code><\/pre>\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 server.js\uc640 server2.js\ud30c\uc77c\uc740 \uc11c\ubc84 \ud30c\uc77c\uc785\ub2c8\ub2e4.<br>The server.js and server2.js files are server files.<\/p>\n\n\n\n<p>\u2714\ufe0f server.js<\/p>\n\n\n\n<p>&#8212; server.js\ud30c\uc77c\uc740 \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c \uac04\ub2e8\ud55c get\ubc29\uc2dd \uba54\uc18c\ub4dc\ub97c \ud14c\uc2a4\ud2b8 \ud560 \uc218 \uc788\ub294 \uc11c\ubc84\uc785\ub2c8\ub2e4.<br>The server.js file is a server that allows you to test simple GET requests from a browser.<\/p>\n\n\n\n<p>&#8212; server.js\uc5d0\ub294 &#8216;\/&#8217;,&#8217;view1&#8242;,&#8217;get1&#8217;\ub77c\uc6b0\ud2b8\uac00 \uc788\uc2b5\ub2c8\ub2e4.<br>server.js contains the routes &#8216;\/&#8217;, &#8216;view1&#8217;, and &#8216;get1&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app.get(\"\/\", (req, res) => { ... }\napp.get(\"\/view1\", (req, res) => { ... }\napp.get(\"\/get1\", (req, res) => { ... }<\/code><\/pre>\n\n\n\n<p>&#8212; \uac04\ub2e8\ud55c \uc608\ub85c get1\ub77c\uc6b0\ud130\ub97c \ud14c\uc2a4\ud2b8\ud558\uba74 \uc544\ub798\ucc98\ub7fc \ube0c\ub77c\uc6b0\uc800\uc640 \ud130\ubbf8\ub110\uc5d0 \ud45c\uc2dc\ub429\ub2c8\ub2e4.<br>As a simple example, if you test the <code>get1<\/code> router, the output appears in the browser and terminal as shown below.<\/p>\n\n\n\n<p>1) \ud130\ubbf8\ub110 \/ Terminal<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"972\" height=\"144\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/terminal-jpg.jpg\" alt=\"\" class=\"wp-image-6255\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/terminal-jpg.jpg 972w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/terminal-jpg-300x44.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/terminal-jpg-768x114.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/terminal-jpg-400x59.jpg 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/terminal-jpg-800x119.jpg 800w\" sizes=\"auto, (max-width: 972px) 100vw, 972px\" \/><figcaption class=\"wp-element-caption\">terminal<\/figcaption><\/figure>\n\n\n\n<p>2)\ube0c\ub77c\uc6b0\uc800 \/ Browser<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"605\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/browser-jpg-1024x605.jpg\" alt=\"\" class=\"wp-image-6256\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/browser-jpg-1024x605.jpg 1024w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/browser-jpg-300x177.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/browser-jpg-768x454.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/browser-jpg-400x236.jpg 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/browser-jpg-800x473.jpg 800w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/browser-jpg.jpg 1056w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">browser<\/figcaption><\/figure>\n\n\n\n<p>\u2714\ufe0f server2.js<\/p>\n\n\n\n<p>&#8212; \uc2e4\ud589\ubc29\ubc95\uc740 server.js\uc640 \uac19\uc2b5\ub2c8\ub2e4.<br>The method for running it is the same as for server.js.<\/p>\n\n\n\n<p>&#8212; server2.js\uc5d0\ub294 server1.js\uc5d0 \ub2e4\uc74c\uacfc \uac19\uc740 \ub77c\uc6b0\ud2b8\uac00 \ub354 \ucd94\uac00\ub418\uc5b4 \uc788\uc2b5\ub2c8\ub2e4.<br>server2.js includes additional routes compared to server1.js, as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app.get(\"\/form\", (req, res) => { ... }\napp.post(\"\/formProc\", (req, res) => { ... }\napp.get(\"\/formapi\", (req, res) => { ... }\napp.post(\"\/api\", (req, res) => { ... }<\/code><\/pre>\n\n\n\n<p>1) \/form \ub77c\uc6b0\ud2b8\ub294 post \uc804\uc1a1\ubc29\uc2dd\uc73c\ub85c formProc\uc5d0 \ub370\uc774\ud130\ub97c \uc804\uc1a1\ud558\uace0 \ube0c\ub77c\uc6b0\uc800\uc640 \ud130\ubbf8\ub110\uc5d0 \uc804\uc1a1\uc815\ubcf4\ub97c \ucd9c\ub825\ud569\ub2c8\ub2e4.<br>The <code>\/form<\/code> route transmits data to <code>formProc<\/code> using the POST method and outputs the transmission information to both the browser and the terminal.<\/p>\n\n\n\n<p>2)\/formapi\ub77c\uc6b0\ud2b8\ub294 post\uc804\uc1a1\ubc29\uc2dd\uc73c\ub85c api\uc5d0 \ub370\uc774\ud130\ub97c \uc804\uc1a1\ud558\uace0 \ube0c\ub77c\uc6b0\uc800\uc640 \ud130\ubbf8\ub110\uc5d0 \uc804\uc1a1\uc815\ubcf4\ub97c json\ub370\uc774\ud130\ub85c \ucd9c\ub825\ud569\ub2c8\ub2e4.<br>The <code>\/formapi<\/code> route transmits data to the API using the POST method and outputs the transmission details as JSON data to both the browser and the terminal.<\/p>\n\n\n\n<p>&#8212; \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c &#8216;from&#8217;\ub77c\uc6b0\ud2b8\ub97c  \uc2e4\ud589\ud569\ub2c8\ub2e4.<br>Execute the &#8216;from&#8217; route in the browser.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"818\" height=\"518\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/form-jpg.jpg\" alt=\"\" class=\"wp-image-6277\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/form-jpg.jpg 818w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/form-jpg-300x190.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/form-jpg-768x486.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/form-jpg-400x253.jpg 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/form-jpg-800x507.jpg 800w\" sizes=\"auto, (max-width: 818px) 100vw, 818px\" \/><figcaption class=\"wp-element-caption\">\/form route<\/figcaption><\/figure>\n\n\n\n<p>&#8212; submit\ubc84\ud2bc\uc744 \ub204\ub974\uba74 form proc\ud654\uba74\uc5d0\uc11c \uc804\uc1a1\uc815\ubcf4\uac00 \ud45c\uc2dc\ub429\ub2c8\ub2e4.<br>When you click the submit button, the transmitted information is displayed on the form processing screen.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"584\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/formProc-jpg.jpg\" alt=\"\" class=\"wp-image-6279\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/formProc-jpg.jpg 750w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/formProc-jpg-300x234.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/02\/formProc-jpg-400x311.jpg 400w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><figcaption class=\"wp-element-caption\">\/formProc route<\/figcaption><\/figure>\n\n\n\n<p>&#8212; \ud130\ubbf8\ub110\uc5d0\ub294 \uc544\ub798\ucc98\ub7fc \ud45c\uc2dc\ub429\ub2c8\ub2e4.<br>It is displayed in the terminal as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Server listening at http:\/\/localhost:3000\nform name : yourname\nform email : test@user.com\nform name : yourname\nform email : test@user.com\nReceived JSON data: { name: 'yourname', email: 'test@user.com' }<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f ejs \ud30c\uc77c \ud638\ucd9c \/ Calling an EJS file<\/p>\n\n\n\n<p>&#8212; server.js\ub098 server2.js\uc5d0\uc11c \uc544\ub798\uc640 \uac19\uc740 \ucf54\ub4dc\ub294 ejs\ud30c\uc77c\uc744 \ud638\ucd9c\ud558\ub294 \ucf54\ub4dc\uc785\ub2c8\ub2e4.<br>In server.js or server2.js, code like the following is used to call an EJS file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>res.render(\"view1\"); \/\/ ejs file<\/code><\/pre>\n\n\n\n<p>&#8212; public \ub514\ub809\ud1a0\ub9ac \uc548\uc5d0 ejs\ud30c\uc77c\uc774 \uc788\uc2b5\ub2c8\ub2e4.<br>There is an EJS file inside the <code>public<\/code> directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- public\nget1.ejs    post1.ejs.    view1.ejs<\/code><\/pre>\n\n\n\n<p>&#8212; ejs\ud30c\uc77c\uc5d0 \uac12\uc774\ub098 \ubcc0\uc218\ub97c \uc785\ub825\ud560\ub54c\ub294 \ub2e4\uc74c\ucc98\ub7fc ejs\ud30c\uc77c\uc744 \ud638\ucd9c\ud569\ub2c8\ub2e4.<br>When passing values \u200b\u200bor variables to an EJS file, you call the EJS file as follows.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>res.render(\"post1\", { fname: name, femail: email });<\/code><\/pre>\n\n\n\n<p>&#8212; \uc11c\ubc84\uc5d0\uc11c \uc8fc\uc785\ub41c \ubcc0\uc218\ub97c ejs\ud30c\uc77c\uc5d0\uc11c\ub294 \uc544\ub798\ucc98\ub7fc \ud45c\ud604\ud569\ub2c8\ub2e4.<br>Variables injected from the server are represented in EJS files as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;h3>post1.ejs&lt;\/h3>&lt;br>\n&lt;h3>name : <strong>&lt;%=fname%><\/strong>&lt;\/h3>&lt;br>\n&lt;h3>email : <strong>&lt;%=femail%><\/strong>&lt;\/h3><\/code><\/pre>\n\n\n\n<p>1)\uc774\ub7f0 \ubc29\uc2dd\uc740 \uae30\uc874\uc758 \uc11c\ubc84\uc0ac\uc774\ub4dc \uc2a4\ud06c\ub9bd\ud2b8(php, asp,jsp)\uc5d0\uc11c \uc0ac\uc6a9\ud558\ub294 \ubc29\uc2dd\uacfc \ub9e4\uc6b0 \uc720\uc0ac\ud569\ub2c8\ub2e4.<br>This approach is very similar to the methods used in traditional server-side scripting (PHP, ASP, JSP).<\/p>\n\n\n\n<p>\u2714\ufe0f html\ud30c\uc77c \ud638\ucd9c<br>Call an HTML file<\/p>\n\n\n\n<p>&#8212; html\ud30c\uc77c\uc744 html \ub514\ub809\ud1a0\ub9ac \ub0b4\uc5d0 \uc788\uc2b5\ub2c8\ub2e4.<br>The HTML file is located in the html directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- html\nindex.html<\/code><\/pre>\n\n\n\n<p>&#8212; server.js\ub098 server2.js\uc5d0\uc11c \uc544\ub798\uc758 \ucf54\ub4dc\ub85c \ud638\ucd9c \ud569\ub2c8\ub2e4.<br>Call it using the code below in server.js or server2.js.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>res.sendFile(path.join(__dirname, \"\/html\", \"\/index.html\"));<\/code><\/pre>\n\n\n\n<p>1) \uc704\uc758 \ucf54\ub4dc\ub294 html \ub514\ub809\ud1a0\ub9ac \ub0b4\uc758 index.html\ud30c\uc77c\uc744 \ud638\ucd9c \ud558\ub294 \ucf54\ub4dc\uc785\ub2c8\ub2e4.<br>The code above calls the index.html file located in the html directory.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb GET,POST \ub370\uc774\ud130 \uc804\uc1a1\ubc29\uc2ddGET,POST METHOD GET and POST Data Transmission Methods \ud83d\udc49\ud83c\udffb nodejs\uc5d0\uc11c \ub370\uc774\ud130 \uc804\uc1a1\ubc29\uc2dd\uc744 \uc124\uba85\ud558\ub294 \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8 \ucf54\ub4dc\uc785\ub2c8\ub2e4.This is JavaScript code that explains data transmission methods in Node.js. \ud83d\udc49\ud83c\udffb MacOS\uc5d0\uc11c \ud14c\uc2a4\ud2b8\ud588\uc9c0\ub9cc \ub300\ubd80\ubd84\uc758 OS\ud658\uacbd\uc5d0\uc11c \ub3d9\uc77c\ud558\uac8c \uc2e4\ud589\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.It was tested on macOS, but it can be run in the same way on most operating systems. \ud83d\udc49\ud83c\udffb [&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,1],"tags":[],"class_list":["post-1142","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\/1142","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=1142"}],"version-history":[{"count":71,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1142\/revisions"}],"predecessor-version":[{"id":6305,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1142\/revisions\/6305"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=1142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=1142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=1142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}