score:0

fetch('urlToFetch').then(res => {
    if(res.ok) {
        console.log(res.json())
    } 
    else {
        console.log('Error')
    }
})
.catch(error => {
    console.log('Error: ' + error.message)
})

score:0

var Sequelize=require('sequelize')

const connection = new Sequelize('mydb', 'postgres', '123456', {
    host: 'localhost',
    dialect:  'postgres' 
  });

  var Emp=connection.define('emp',{
    fullName: {
        type: Sequelize.STRING
      },
      email: {
        type: Sequelize.STRING
      }    
})

module.exports ={

   
// employee details fetched
    empdetails: function empdetails(req,res,next){
        // res.send('employee details ')
        connection.sync().then(function(){
            Emp.findAll().then(function(emps,error){
                           
                          //make sure you can return response
                      res.status(200).send({
                      data: emps,
                      message: "Success business list",
                       status: 0,
                });
              })
          })
    },
// employee details by ID
    empdetails_id: function empdetails_id(req,res,next){
        res.send('employee details of :  '+req.params.id)
        connection.sync().then(function(){
            Emp.findByPk(req.params.id).then(function(emps,error){

                          res.status(200).send({
                      data: emps,
                       message: "Success business list",
                    status: 0,
        });
              })
          })
    },
    
 };

Related Query

More Query from same tag