I am new nodejs coder. In my study, I want to display data in the browser after saving data in mongodb collection.
I am able to save a data in mongodb, but can't show or dipslay data in browser as I plan it to be
After submit, i can save the data in DB, but I would want to either
display in browser the MOST RECENT (based on date) saved/inserted data in DB or
the temperature gotten from the source website
This is the code snippet
const express = require('express');
const dotenv = require("dotenv").config();
const address = process.argv[2];
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const app = express();
//INSERT TO MONGO DB
//connect to mongo db
mongoose.connect('mongodb://localhost/weathertest2');
mongoose.Promise = global.Promise;
//create weather schema
const WeatherSchema = new Schema({
location:{
type: String
},
temperature:{
type: String
},
observationTime:{
type: String
}
});
const Weather = mongoose.model('weather', WeatherSchema);
// post request
app.post('/new', function(req, res){
new Weather({
location : req.body.location,
temperature: req.body.temperature,
observationTime : req.body.observationTime
}).save(function(err, doc){
if(err) res.json(err);
else res.send(req.body.location);
});
});
// listen for request
app.listen(process.env.port || 9000, function(){
console.log('now listening for testing request');
});
app.use(express.static('public'));

res.send(req.body.location)is called after submission, it should show your location data in response. in case you want to show this data use template engine such as ejs, pug, handlebarjs etc