Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use console.log in EJS

Is it possible to use console.log in a node / ejs template? It doesn't seem to do anything when I try, even something as simple as:

<% console.log('test') %>

I've also tried:

<%= console.log('test') %>

Nothing shows up in the console.

like image 488
Mankind1023 Avatar asked Nov 20 '16 23:11

Mankind1023


People also ask

Can you console log in EJS?

console. log() in EJS file will show the log in the terminal where the server is running.

What is EJS file?

EJS (Embedded JavaScript Templating) is one of the most popular template engines for JavaScript. As the name suggests, it lets us embed JavaScript code in a template language that is then used to generate HTML.


3 Answers

I think you are expecting it to show in the developer console. It will not show up there. console.log() in EJS file will show the log in the terminal where the server is running.

like image 115
Shubham Gupta Avatar answered Oct 19 '22 21:10

Shubham Gupta


This worked perfectly

<% console.log('heheeh', JSON.stringify(doc, null, '\t')) %>

like image 40
lamnv60533 Avatar answered Oct 19 '22 21:10

lamnv60533


console.log() is working fine, but its log does not display in dev tools.
So, check your terminal first:

<% console.log("test") %> 

It's perfect.

like image 3
Praveen Patel Avatar answered Oct 19 '22 21:10

Praveen Patel