display article in database but it has html tag

117 Views Asked by At

I'm creating a web using nodejs, ExpressJS, EJS and MySQL. I save some data with HTML code in MySQL. When I get data from MySQL and show in web,an error occur: HTML tag in data also showing with data. How can you help me solve this problem. Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

Try to pass your output through a function such as:

function escapeHtml(unsafe) {
    return unsafe
         .replace(/&/g, "&")
         .replace(/</g, "&lt;")
         .replace(/>/g, "&gt;")
         .replace(/"/g, "&quot;")
         .replace(/'/g, "&#039;");
 }

Shamelessly copied from here.