2020-09-28-nodejs
Step 1: Dependencies
Install dependencies.
npm i express mongoose mongoose-paginate-v2 --save
npm i nodemon --save-devStep 2: Tutorial Schema
Create file - ./models/Tutorial.js & copy-paste contents as follows.
const mongoose = require("mongoose");
const mongoosePaginate = require("mongoose-paginate-v2"); // 1. import
const schema = new mongoose.Schema({
title: { type: String, index: true, required: true },
description: { type: String, index: true },
published: { type: Boolean, required: true },
createdAt: { type: Date, default: Date.now },
updatedAt: { type: Date, default: Date.now }
});
schema.plugin(mongoosePaginate); // 2. Added plugin
const Tutorial = mongoose.model("Tutorial", schema);
module.exports = Tutorial;Step 3: Mongo Connection
Create file - ./config/keys.js
Step 4: Tutorial Route with Pagination
e.g. Routes are
localhost:5000/tutorialCreate file
./routes/tutorial.js
Step 5: App.js
Previous2019-04-12-14-JekyllGenerateCategoriesPageNext2020-07-03-Android-Kotlin-Clickable-RecyclerView
Last updated
Was this helpful?