Gaurav Kumar
Gaurav Kumar

Reputation: 718

Make Visual Studio Code IDE Recognize EJS Variable in Javascript

I am making a project in Nodejs with express framework i am using EJS as template engine, i use Visual Studio Code as a IDE.

I have a strange problem where when i use EJS variable inside <script> tag in same ejs file it renders correctly and woks as expected but Visual studio Code marks it an error saying JS Expression Expected

 <% 
    var date = matches.dateGMT;
    var matchDate = date.getTime();
  %> 

  <script type="text/javascript">
    $(function () {
        var date = <%= matchDate %> ;
        var dateUntil = new Date(date);
        $('.match_time').countdown({until: dateUntil});
    });
  </script> 

Screenshot from IDE

enter image description here

Any one has idea how to get rid of this error showing in Visual Studio Code.

Upvotes: 5

Views: 3813

Answers (1)

metamemelord
metamemelord

Reputation: 528

I use VSCode for my Express applications as well. I have installed the JavaScipt EJS plugin by Digital Brainstem, and everything works fine.

Also, just a suggestion (as JS is not my first language), you can probably take the matchDate as an argument to the function and then wrap it around an event. It'll just increase the overall readability of the code. Rest is personal preference.

Upvotes: 4

Related Questions