1

I only get [object Object] when I use EJS to render the data from MySQL. JSON.parse does not work as well with this string: "JSON.parse: unexpected character at line 1 column 2 of the JSON data"

app.get("/favorites", function(req, res) {
  var favorites = {};
  db.query("SELECT * FROM favs WHERE user_id = '1'", function (error, result, fields) {
    if (error) throw error;
    favorites = result;
    res.render("favorites", {data: {print: favorites, page: true}});
  });
});
console.log("<%= data.print %>");
<!-- [object Object] -->

1 Answer 1

1

You have an object. You don't need to parse it, but to stringify it:

res.render("favorites", JSON.stringgify({data: {print: favorites, page: true}}));
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.