5

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.

2
  • Visual Studio Code initially doesn't support EJS, but you can look at plugins Commented Apr 1, 2018 at 9:01
  • @Duoxx ....can you suggest any good plugin because last time used one it was clashing with existing rules of VSC and i had to uninstall it. Commented Apr 1, 2018 at 9:18

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks that JavaScript EJS Plugin By Digital Brainstem really worked
update , the mentioned plug-in worked for this but started giving other problems

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.