Im trying to have the current date as an object property and convert it to Json for node back end. I also don't know if the date property in node will capture the instance from the front end
In angular 2/4 i have
const newCustomer = {
firstName: this.firstName;
lastName: this.lastName;
date: number = Date.now();
}
My router.post in node
router.post('/customers', (req,res,next) =>{
let newCustomer = new Customer({
firstName: req.body.firstName,
lastName: req.body.lastName,
date: Date.now()
});
newCustomer.save(function(err, Customer){
if (err){
res.json({msg: 'Failed to add contact'});
}else{
res.json({msg: 'Customer added to waitlist'});
}
});
My model/Schema for customer
const customerSchema = new Schema({
date: new Date();
firstName: {
type: String,
//required means there has to be a name
required: true
},
lastName: {
type: String,
required: true
}
});
via TexasState Han
No comments:
Post a Comment