I am beginner in nodejs and reactjs, I develope an application from reactjs and nodejs, and i use postgresql for database , when i try to fetch employeedetails by calling api in server.js that time it shows datalogs in VScode console, but If i see in developer console in my browser then there is no data fetched from database, anyone help me to solve this problem?
server.js
var restify=require('restify')
const {empdetails,empdetails_id } = require('./Function');
var server=restify.createServer() //server created
server.get('/empdetails',empdetails)
server.get('/empdetails_id/:id',empdetails_id)
server.listen(8080, function(){
console.log("server started...")
})
function.js
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){
console.log(emps)
var sample=emps
console.log(sample)
res.send(emps);
})
})
},
// 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){
console.log(emps)
})
})
},
};