0
    SyntaxError: Unexpected token ')' in C:\Users\hp\short.nner\views\index.ejs while compiling ejs

If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
    at new AsyncFunction (<anonymous>)
    at Template.compile (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:661:12)
    at Object.compile (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:396:16)
    at handleCache (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:233:18)
    at tryHandleCache (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:272:16)
    at View.exports.renderFile [as engine] (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:489:10)
    at View.render (C:\Users\hp\short.nner\node_modules\express\lib\view.js:135:8)
    at tryRender (C:\Users\hp\short.nner\node_modules\express\lib\application.js:640:10)
    at Function.render (C:\Users\hp\short.nner\node_modules\express\lib\application.js:592:3)
    at ServerResponse.render (C:\Users\hp\short.nner\node_modules\express\lib\response.js:1012:7)
    at C:\Users\hp\short.nner\server.js:49:17
    at processTicksAndRejections (node:internal/process/task_queues:93:5)

Here's my code:

    <%=Url.forEach(shortUrl => { %>
                    <tr>
                        <td>
                            <a href="<%= shortUrl.full %>">
                                <%= shortUrl.full %>
                            </a>
                        </td>
                        <td>
                            <a href="<%= shortUrl.short %>">localhost:3000/<%= shortUrl.short %></a
              >
            </td>
            <td><%= shortUrl.clicks %></td>
            <td><%= shortUrl.GivenEmail %>
          </tr>
          <% }) %>

I really don't know why I am getting this error please help. I did give the Url as an option to my ejs but I get this strange error on running it.

10
  • sorry i published wrong title by mistake Commented Jan 1, 2021 at 13:52
  • have edited it now Commented Jan 1, 2021 at 13:52
  • <%=Url.forEach(shortUrl => { %> looks incomplete. Commented Jan 1, 2021 at 14:27
  • i used this const Url = await ShortUrl.find({ realEmail: email}); in my server.js . Is there something wrong with it? Commented Jan 1, 2021 at 14:51
  • if i remove '=' from 1st line I just see {} on my site. Commented Jan 1, 2021 at 15:08

1 Answer 1

1

I wasn't able to fully test your code yesterday because I was on mobile.

The problem is actually coming from the = in the beginning of <%=Url.forEach(shortUrl =>. Just remove it like this should work:

 <% Url.forEach(shortUrl => { %>
                    <tr>
                        <td>
                            <a href="<%= shortUrl.full %>">
                                <%= shortUrl.full %>
                            </a>
                        </td>
                        <td>
                            <a href="<%= shortUrl.short %>">localhost:3000/<%= shortUrl.short %></a
              >
            </td>
            <td><%= shortUrl.clicks %></td>
            <td><%= shortUrl.GivenEmail %>
          </tr>
          <% }) %>

That should dismiss the error.

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

Comments

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.