Express js CRUD Tutorial using mongodb.(Show)

1. app.js

2. homeController.js

exports.getAllUser = async (req, res, next) => {
let user_data = await user_model.find()
res.render('show',{user_data})
}

3. Create Show.ejs file:

blog_expressjs/views/show.ejs<table class="table">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Description</th>
<th>Action</th>
</tr>
</thead>
<tbody>

<% for(let p of user_data) { %>
<tr>
<th><%= p.id %></th>
<td><%= p.title %></td>
<td><%= p.description %></td>
<td>
<a class="btn btn-md btn-success">Edit</a>
<a class="btn btn-md btn-danger">Delete</a>
</td>
</tr>
<% } %></tbody>
</table>

--

--

Senior Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store