Displaying Success or Error messages in EJS

I'm a beginner at Nodejs, Express, and EJS. I'm doing an assignment about a simple action form. However, I don't know how to display whenever the request is a success or failure on the result page.

This is what I have done so far: https://stackblitz.com/edit/express-simple-pu956p?file=README.md

I was trying to add the following code below, but it didn't work.


.then((response) => {
      var datas = response.data.results;
      console.log('Superhero Input:', superhero);
      res.render('pages/results', { datas: datas, message: 'success', type: 'success' });
.catch((error) => {
      res.render('pages/results', { message: error.message, type: 'danger' });

res.render the message to somewhere in


<% if (locals.type, locals.message) { %>
   <div class="alert alert-<%= type %>" role="alert">
       <strong> <%= message %> </strong>
<% } %>
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum