Building an e-Commerce website with Node – Part 29 – Create category page in Node.js

We are going to create the add-category.ejs page. It has to be under the views/admin folder. Create the admin folder under the views folder and within the admin folder create a file named add-category.ejs. Type the folowing code into the add-category.ejs file.

<% layout('layout') -%>

<div class="row">
  <div class="col-lg-6 col-md-offset-3">

    <% if (message.length > 0) { %>
      <div class="alert alert-success alert-dismissible">
        <button type="button" class="close" data-dismmiss="alert" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          <%= message %>
    <% } %>

    <form method="post">

      <h1> Add a new Category </h1>
      <div class="form-group">
        <label="name">Name: </label>
        <input type="text" class="form-control" name="name">

      <button type="submit" class="btn btn-success">Submit</button>


Before going any further we have to require this file in the server.js. Let’s go and create a new route in server.js file. Add the following two lines of code to the server.js file.

var adminRoutes = require('./routes/admin');



Now, start the server and visit http://localhost:3000/add-category. Of course, you don’t want everybody to add categories. Only an admin should be able to add a category. For that we need to add a security layer (but in another post).

Leave a Reply