how to use another page urls from running page and how to create router |, rest api ain nodejs nodejstututorials

 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

React -1 ( react with ravenndra kanchi)

 react with tool chanis 45 to 50 sessions core  after 50 sessions -> some tooll chains == react with type script mern stackaplication in ...