Dynamic EJS

About This Space

Demo app to use EJS to display information from a database


Last updated on November 11, 2021

Public Permissions:   View   Open/Fork   Run   Comment  

Dynamic EJS List Template

This template illustrates how to use EJS to display information from a database.

What is EJS?

EJS is a simple templating language that lets you generate HTML markup using dynamic data from a Node.js script. For more information, visit http://ejs.co.

Setup

Generally, you will need 2 files to implement EJS:

  • A Node.js file to produce the data for the ejs template (list.js)
  • An EJS file for the HTML template (list.ejs)

response.render() connects the Node.js code to the EJS file. For example:

function list(request, response) {  
  var customers = pjs.query("SELECT customerName FROM customers");
  response.render("list.ejs", { customers });
}

The Node.js file must be setup as an Express route:

Screenshot

To get to this dialog, right-click the file in the Files tree and select Properties.

Comments

Write Preview Markdown: bold italic code link
Post

5 years ago

Great work, saidur!

5 years ago

Thanks, Alex. I didn't notice your comment until today. I didn't know anybody was watching :)

More Spaces By Saidur (@saidur)

Filters:

Popular Recent

Just a cool demo of how to use other npm packages on NodeRun!

5515

0

0

Vue.js Application

6003

0

0

Vue.js using Rich Display Components built in the Visual Designer

5718

0

0