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

Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...