the domain.js code is as follows
var mongoose = require("mongoose")
var moment = require("moment")
var Schema = mongoose.Schema
function dateformat(val) {
console.log("dateformat" + val);//
return moment(val).format("YYYY-MM-DD");
}
var schema = new Schema({
id: Number,
domain: String,
title: {
type: String
},
keyword: String,
describe: String,
date: {
type: Date,
default: Date.now,
get: dateformat //get,dateformat(),
}
})
module.exports = schema
the express.js code is as follows
var express = require("express");
var domains = require("../../models/domains")//models ,schemadomain.js
var router = express.Router();
var info = {}
router.get("/domain", async (req, res) => {
var domaindb
where = {}
domaindb = domains.findOne(where).exec()
domaindb = await domaindb
console.log(domaindb)//domaindb,date,.
if (domaindb) {
info.code = 0
info.message = domaindb
} else {
info.code = -1
info.message = ""
}
return res.json(info);
});