0

Im creating a website where I show today's date with ejs, formatted with momentjs. Here is my code:

<h1>Eduardo's Contact List</h1>
  <% var a = moment().format("MMMM Do YYYY"); %>
        <p>Today is <%= a %></p>

An error appears saying that moment is not defined. I run into this problem regardless if I call the script in the head or right before the closing body tag.

However, when I run the program without calling the functions, I can use moment in the console, meaning that I am calling the moment script correctly.

Are momentjs and embeddedjs incompatible? What am I doing wrong?

  • Possible duplicate of [JavaScript that executes after page load](https://stackoverflow.com/questions/807878/javascript-that-executes-after-page-load) – André Dion Mar 25 '18 at 19:51

1 Answers1

0

Pretty simple solution:

I placed the variable in a js script as such:

var today = moment().format("MMMM Do YYYY");
document.getElementById("today").textContent= "Today is " + today;

Made sure to call it after calling the momentjs script.

Did not need to use ejs.