Express js CRUD Tutorial using mongodb.(Show)

1. app.js

const allController = require('./homeController')
app.get('/show', allController.getAllUser)

2. homeController.js

const user_model = require('./user_model') // include user_model.jsexports.getAllUser = async (req, res, next) => {
let user_data = await user_model.find()
res.render('show',{user_data})
}

3. Create Show.ejs file:

vim show.ejsblog_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>

--

--

--

Software Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Event Sequence Diagram in JavaScript

Typescript method overloading

JavaScript: auto update all of doms’ value when variable was updated

How to Load Data Easily With React Hooks

Deploying Nodejs pm2 to Ubuntu 20.0

Ways of Styling in react-native

Top Webpack plugins for faster development

How to create an Ionic 4 app  —  For beginners

How to create an Ionic 4 app — For beginners

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
Safaetul Ahasan

Safaetul Ahasan

Software Engineer

More from Medium

Node Js With MongoDB

Minima NodeJS — with examples

What is Mongoose?