title: SPA w/ Node.JS and Express and .ejs
body: <p>How would you show parsed data on a single page app. For instance, I am able to console.log the quotes generated from the API, but I'm not sure how to post them on the single page.</p>
  
  <p>Index.ejs:</p>
  
  <pre><code>&lt;% include ./partials/header %&gt; 
  &lt;div class=container&gt;
      &lt;h1&gt;Free2BGeek&lt;/h1&gt;
      &lt;h3&gt;This is your joke for the day!&lt;/h3&gt;
      &lt;hr&gt;
      &lt;p&gt;
          "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse sit amet turpis ex. Vivamus aliquet ipsum tortor, at rhoncus ligula efficitur condimentum. Sed pretium arcu quis ex fringilla, et consectetur odio sodales."
      &lt;/p&gt;
  &lt;/div&gt;
  &lt;% include ./partials/footer %&gt; 
  </code></pre>
  
  <p>app.js</p>
  
  <pre><code>const express        = require("express"),
        app            = express(),
        request        = require("request"),
        bodyParser     = require("body-parser"),
        mongoose       = require("mongoose");
  
  mongoose.connect("mongodb://localhost:27017/geek-jokes", { useNewUrlParser: true });
  mongoose.set('useFindAndModify', false);
  app.set("view engine", "ejs");
  app.use(express.static("public"));
  app.use(bodyParser.urlencoded({extended: true}));
  
  app.get("/", function(req, res){
      res.render("index");
  });
  
  let options = {
      url: 'https://geek-jokes.sameerkumar.website/api',
      method: 'GET'
  };
  request(options, (err, response, body) =&gt; {
      if(!err &amp;&amp; response.statusCode == 200)
          var parsedData = JSON.parse(body);
          console.log(parsedData);
  });
  
  app.get("*", function(req, res){
      res.send("Error - I'm sorry, the page you tried to get to either does not exist or has been removed.");
  });
  app.listen(process.env.PORT, process.env.IP, function(){
      console.log("Geeks are ready!");
  });
  </code></pre>
  
  <p>I want to be able to replace the Lorem Ipsum text with the joke.</p>
  
  <p>My current results look like:</p>
  
  <p><a href="https://i.stack.imgur.com/qX2y6.png" rel="nofollow noreferrer">Index Page</a></p>
  
  <p>I tried to put</p>
  
  <pre><code>&lt;p&gt;
     &lt;%= options %&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>But I only get an error. Should I be using a POST route to replace the ext with? OR is there another way to embed the quote from the api?</p>
  
  <p>===========================================================================</p>
  
  <p>Thank you both to <em><strong>THEWOLF</strong></em> and <em><strong>Lawrence Cherone</strong></em>. The code was updated in the <strong>app.js</strong> file and is as follows:</p>
  
  <pre><code>const express        = require("express"),
        app            = express(),
        request        = require("request"),
        bodyParser     = require("body-parser"),
        mongoose       = require("mongoose");
  
  var url = process.env.DATABASEURL || "mongodb://localhost:27017/geek-jokes";
  mongoose.connect(url);
  
  mongoose.set('useFindAndModify', false);
  
  app.set("view engine", "ejs");
  
  app.use(express.static("public"));
  
  app.use(bodyParser.urlencoded({extended: true}));
  
  app.get("/", function(req, res){
          let options = {
              url: 'https://geek-jokes.sameerkumar.website/api',
              method: 'GET'
      };
  
      request(options, (err, response, body) =&gt; {
          if(!err &amp;&amp; response.statusCode == 200)
              var parsedData = JSON.parse(body);
              console.log(parsedData);
              res.render("index", {body: parsedData });
      });
  });
  
  app.get("*", function(req, res){
      res.send("Error - I'm sorry, the page you tried to get to either does not exist or has been removed.");
  });
  
  app.listen(process.env.PORT, process.env.IP, function(){
      console.log("Geeks are ready!");
  });
  </code></pre>