{"id":698,"date":"2024-08-15T06:29:47","date_gmt":"2024-08-15T06:29:47","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=698"},"modified":"2024-08-15T15:38:13","modified_gmt":"2024-08-15T15:38:13","slug":"nodejsejs-using-ejs","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2024\/08\/15\/nodejsejs-using-ejs\/","title":{"rendered":"[nodejs]EJS\uc0ac\uc6a9\ud558\uae30\/Using EJS &#8211; 1"},"content":{"rendered":"\n<p>\ube0c\ub77c\uc6b0\uc800\uc758 \uc6f9\ud398\uc774\uc9c0\uc5d0\uc11c \ubc14\ub85c \ubb3c\ub9ac\uc801\uc778 \uc11c\ubc84\uc5d0\uc811\uadfc\ud558\ub294\uac83\uc774 \uae30\ubcf8\uc801\uc73c\ub85c\ub294 \ubd88\uac00\ub2a5\ud569\ub2c8\ub2e4.<br>\uadf8\ub798\uc11c asp,php,jsp\uac19\uc740 Server side script\uac00 \ub9cc\ub4e4\uc5b4\uc84c\uc2b5\ub2c8\ub2e4.<br> asp,php,jsp\ub97c \uc0ac\uc6a9\ud574\ubcf4\uc2e0 \ubd84\ub4e4\uc774 EJS(Embedded JavaScript templates for node)\ub97c \uc0ac\uc6a9\ud558\uba74 \uc774\ud574\uac00 \uc27d\uc2b5\ub2c8\ub2e4.<br>\uae30\uc874\uc758 server-side script\uc5b8\uc5b4\uc640 \ub9e4\uc6b0 \uc720\uc0ac\ud55c \uc810\uc774 \ub9ce\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<p>It is basically impossible to access the physical server directly from the browser&#8217;s web page.<br>So, server side scripts such as asp, php, and jsp were created.<br>For those who have experience with asp, php, and jsp, it is easy to understand using EJS (Embedded JavaScript templates for node).<br>It has many similarities to existing server-side script languages.<\/p>\n\n\n\n<p>React\uc640 \ube44\uad50\ud574\ubcf4\uc790\uba74 React\ub294 1\ud398\uc774\uc9c0 \uc5b4\ud50c\ub9ac\ucf00\uc774\uc158\uc73c\ub85c \uc774\ubca4\ud2b8 \ubc1c\uc0dd\uc2dc \ucef4\ud3ec\ub10c\ud2b8\ub97c \uad50\uccb4\ud558\ub294 \ubc29\ubc95\uc73c\ub85c \ud398\uc774\uc9c0\ub97c \uad6c\ud604\ud55c\ub2e4\uba74 EJS\ub294 \ud30c\uc77c\uc744 include\ud558\uac70\ub098 node server \ud398\uc774\uc9c0\uc5d0\uc11c \ubcc0\uc218,\ubc30\uc5f4,\uac1d\uccb4\ub4f1\uc744 ejs\ud30c\uc77c\ub85c \uc804\ub2ec\ud569\ub2c8\ub2e4.<\/p>\n\n\n\n<p>Compared to React, React is a one-page application that implements the page by replacing components when an event occurs, but EJS includes files or transfers variables, arrays, and objects from the node server page to the ejs file.<\/p>\n\n\n\n<p>\uc791\uc5c5\ud658\uacbd\uc740 \uc800 \uac19\uc740 \uacbd\uc6b0 \uc708\ub3c4\uc6b0pc+visual studio code\ub85c \uc791\uc5c5\ud558\uace0 oci linux server\ub85c \ud30c\uc77c\uc744 \uc5c5\ub85c\ub4dc \ud569\ub2c8\ub2e4.<br>\uc544\ub798\ub294 \uc708\ub3c4\uc6b0\ud658\uacbd\uc5d0\uc11c\uc758 \uc124\uce58 \ubc29\ubc95\uc774\uc9c0\ub9cc \ub9ac\ub205\uc2a4\ud658\uacbd\uc5d0\uc11c\ub3c4 \ub3d9\uc77c\ud55c \uba85\ub839\uc5b4\ub97c \uc0ac\uc6a9\ud558\uc2dc\uba74 \ub429\ub2c8\ub2e4.<br>ftp\ub85c \ud30c\uc77c\uc5c5\ub85c\ub4dc\ud558\ub294 \ubd80\ubd84\uc740 \uc0dd\ub7b5\ud588\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<p>In my case, I upload files to the Oci Linux server using PC+visual studio code.<br>Below is the installation method in a Windows environment, but you can use the same command in a Linux environment.<br>I omitted the part about uploading files via ftp.<\/p>\n\n\n\n<p>\uc544\ub798\ub294 \uac04\ub2e8\ud788 EJS\ub97c \uc0ac\uc6a9\ud558\ub294 \ubc29\ubc95\uc785\ub2c8\ub2e4.<br>Below is a simple way to use EJS.<br><\/p>\n\n\n\n<p><strong>1.\ud504\ub85c\uc81d\ud2b8\uc2dc\uc791(Project start)<\/strong><br>&#8211; npm init \uba85\ub839\uc5b4\ub85c nodejs\ud504\ub85c\uc81d\ud2b8\ub97c \uc2dc\uc791\ud574\uc11c package.json\ud30c\uc77c\uc744 \uc0dd\uc131\ud569\ub2c8\ub2e4.<br>&#8211; \uadf8\ub0e5 \uc9c8\ubb38\uc5d0 \ubaa8\ub450 \uc5d4\ud130\uce58\uba74 \ub514\ud3f4\ud2b8 \uac12\uc73c\ub85c \ud504\ub85c\uc81d\ud2b8 \uc2dc\uc791\ud569\ub2c8\ub2e4.<\/p>\n\n\n\n<p>Start the nodejs project with the npm init command and create a package.json file.<br>Just press Enter on all questions and the project will start with default values.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"565\" height=\"751\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/npm_init.png\" alt=\"\" class=\"wp-image-702\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/npm_init.png 565w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/npm_init-226x300.png 226w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/><\/figure>\n\n\n\n<p><strong>2.\ubaa8\ub4c8\uc124\uce58(Module installation)<\/strong><br>&#8211; npm install express path ejs &#8211;save \uba85\ub839\uc5b4\ub85c ejs\ubaa8\ub4c8 \ubc0f express,path\ubaa8\ub4c8\uc744 \uc124\uce58\ud569\ub2c8\ub2e4 <br>&#8211; ejs\ub9cc \uc124\uce58\ud560\uacbd\uc6b0 npm install ejs &#8211;save \uba85\ub839\uc5b4\ub97c \uc0ac\uc6a9\ud558\uc2dc\uba74 \ub429\ub2c8\ub2e4.<\/p>\n\n\n\n<p>Install the ejs module and express, path module with the npm install express path ejs &#8211;save command.<br>If you want to install only ejs, use the npm install ejs &#8211;save command.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"526\" height=\"188\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/npm_install_module.png\" alt=\"\" class=\"wp-image-704\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/npm_install_module.png 526w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/npm_install_module-300x107.png 300w\" sizes=\"auto, (max-width: 526px) 100vw, 526px\" \/><\/figure>\n\n\n\n<p><strong>3.node \uc11c\ubc84 \ud30c\uc77c \uc0dd\uc131(Create node server file)<\/strong><br>&#8211; server.js\ud30c\uc77c\uc744 \uc0dd\uc131\ud569\ub2c8\ub2e4. Create a server.js file.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"534\" height=\"636\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/server.js.png\" alt=\"\" class=\"wp-image-705\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/server.js.png 534w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/server.js-252x300.png 252w\" sizes=\"auto, (max-width: 534px) 100vw, 534px\" \/><\/figure>\n\n\n\n<p><strong>4.public\ub514\ub809\ud1a0\ub9ac \ub9cc\ub4e4\uace0 \uc544\ub798\uc5d0 test.ejs\ud30c\uc77c\uc744 \uc0dd\uc131\ud569\ub2c8\ub2e4.<\/strong><br>Create a public directory and create a test.ejs file below.<br>&#8211; \ub8e8\ud2b8 \ub514\ub809\ud1a0\ub9ac(root directory)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"404\" height=\"234\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/serverDirectory.png\" alt=\"\" class=\"wp-image-707\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/serverDirectory.png 404w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/serverDirectory-300x174.png 300w\" sizes=\"auto, (max-width: 404px) 100vw, 404px\" \/><\/figure>\n\n\n\n<p>-test.ejs\ud30c\uc77c\uc0dd\uc131 (Create a test.ejs file)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"456\" height=\"205\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/test.ejs_.png\" alt=\"\" class=\"wp-image-708\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/test.ejs_.png 456w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/test.ejs_-300x135.png 300w\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" \/><\/figure>\n\n\n\n<p><strong>5.node\uc11c\ubc84 \uc2dc\uc791 \ubc0f ejs\ud30c\uc77c \ud14c\uc2a4\ud2b8(node server test and ejs file test)<\/strong><br>&#8211; node server start(linux)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"589\" height=\"299\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/nodeserverstart-1.png\" alt=\"\" class=\"wp-image-710\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/nodeserverstart-1.png 589w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/nodeserverstart-1-300x152.png 300w\" sizes=\"auto, (max-width: 589px) 100vw, 589px\" \/><\/figure>\n\n\n\n<p>&#8211; \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c ejs\ud30c\uc77c \uc2e4\ud589(run ejs file in browser)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"467\" height=\"351\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/browger.png\" alt=\"\" class=\"wp-image-711\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/browger.png 467w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/browger-300x225.png 300w\" sizes=\"auto, (max-width: 467px) 100vw, 467px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\ube0c\ub77c\uc6b0\uc800\uc758 \uc6f9\ud398\uc774\uc9c0\uc5d0\uc11c \ubc14\ub85c \ubb3c\ub9ac\uc801\uc778 \uc11c\ubc84\uc5d0\uc811\uadfc\ud558\ub294\uac83\uc774 \uae30\ubcf8\uc801\uc73c\ub85c\ub294 \ubd88\uac00\ub2a5\ud569\ub2c8\ub2e4.\uadf8\ub798\uc11c asp,php,jsp\uac19\uc740 Server side script\uac00 \ub9cc\ub4e4\uc5b4\uc84c\uc2b5\ub2c8\ub2e4. asp,php,jsp\ub97c \uc0ac\uc6a9\ud574\ubcf4\uc2e0 \ubd84\ub4e4\uc774 EJS(Embedded JavaScript templates for node)\ub97c \uc0ac\uc6a9\ud558\uba74 \uc774\ud574\uac00 \uc27d\uc2b5\ub2c8\ub2e4.\uae30\uc874\uc758 server-side script\uc5b8\uc5b4\uc640 \ub9e4\uc6b0 \uc720\uc0ac\ud55c \uc810\uc774 \ub9ce\uc2b5\ub2c8\ub2e4. It is basically impossible to access the physical server directly from the browser&#8217;s web page.So, server side scripts such as asp, php, and jsp were created.For [&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-698","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\/698","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=698"}],"version-history":[{"count":9,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/698\/revisions"}],"predecessor-version":[{"id":717,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/698\/revisions\/717"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}