Connect Server with Express Engine- EJS Work as a Frontend

many of user does not understand how we create our data to frontend in react so this article help for you.

first we install

npm install ejs

then set some cofigurations in your project

first make folder views
app.set(‘view engine’,’ejs’);


This content originally appeared on DEV Community and was authored by Deepak

many of user does not understand how we create our data to frontend in react so this article help for you.

first we install

npm install ejs

then set some cofigurations in your project

  • first make folder views app.set('view engine','ejs');

index.ejs


`<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Express Engine</title>
</head>
<body>
    <%= heading  %> 
</body>
</html>`

in our index.js we simple render the page index.ejs

`app.get('/',(req,res)=>{

   res.render('index.ejs',{heading:"first Page"});
})`

EJS work as a component based like in react

simply use include file

include('header.ejs')

some developers are think ejs is tough for us but dont worry about this is a simple like you work on html but some operation map array of content then use it like you use php as server .
<% array.forEach(item=>{}) %>`

we can do everything using ejs.


This content originally appeared on DEV Community and was authored by Deepak


Print Share Comment Cite Upload Translate Updates
APA

Deepak | Sciencx (2021-12-19T05:05:01+00:00) Connect Server with Express Engine- EJS Work as a Frontend. Retrieved from https://www.scien.cx/2021/12/19/connect-server-with-express-engine-ejs-work-as-a-frontend/

MLA
" » Connect Server with Express Engine- EJS Work as a Frontend." Deepak | Sciencx - Sunday December 19, 2021, https://www.scien.cx/2021/12/19/connect-server-with-express-engine-ejs-work-as-a-frontend/
HARVARD
Deepak | Sciencx Sunday December 19, 2021 » Connect Server with Express Engine- EJS Work as a Frontend., viewed ,<https://www.scien.cx/2021/12/19/connect-server-with-express-engine-ejs-work-as-a-frontend/>
VANCOUVER
Deepak | Sciencx - » Connect Server with Express Engine- EJS Work as a Frontend. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/19/connect-server-with-express-engine-ejs-work-as-a-frontend/
CHICAGO
" » Connect Server with Express Engine- EJS Work as a Frontend." Deepak | Sciencx - Accessed . https://www.scien.cx/2021/12/19/connect-server-with-express-engine-ejs-work-as-a-frontend/
IEEE
" » Connect Server with Express Engine- EJS Work as a Frontend." Deepak | Sciencx [Online]. Available: https://www.scien.cx/2021/12/19/connect-server-with-express-engine-ejs-work-as-a-frontend/. [Accessed: ]
rf:citation
» Connect Server with Express Engine- EJS Work as a Frontend | Deepak | Sciencx | https://www.scien.cx/2021/12/19/connect-server-with-express-engine-ejs-work-as-a-frontend/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.