u already seen this below code in above programms or previus posts
create router folder
in thgat create productRouter.js
const express = require('express');
const app = express();
var mongoose= require("mongoose");
var Persons=require("../models/personSchema,js");
var productRouter = express.Router();
var bodyParser = require('body-parser');
productRouter.use(bodyParser.json());
productRouter.route('/')
.get(function (req,res)
{
Persons.find({}, function(err,person)
{
if(err) throw err;
res.json(person);
})
})
module.exports= productRouter;
in index.js
import and use this file
var productRouter = require('./router/productRouter');
use
app.use('/products', productRouter);
http://localhost:3000/products/
if u hit this api - u can get
all the things in product page
No comments:
Post a Comment