Node js api

Asked by Andre about 2 years ago


Hello guys, My name is Micahael. I have been developing node js app to collect report from site workers using forms. So far, I have been able to post to mongoDB collection using a post route in my server js. However, I have been finding it difficult to retrieve the data from the collection and displaying it in my admin.html page. I didn't use any template engine. I want to use a get route in the server.js to display the data on my admin.html page.Here is my model. Thanks in advance. //user.js const mongoose = require("mongoose");

const GeneratorSchema = new mongoose.Schema( { location: { type: String, required: true }, manager: { type: String }, month: { type: Date, default: }, capacity1: { type: Number }, usage1: { type: Number }, runtime1: { type: Number }, capacity2: { type: Number }, usage2: { type: Number }, runtime2: { type: Number }, genOption: { type: String, possibleValues: ['yes','no'] } }, { collection: 'gen_report'} );

const Generator = mongoose.model('Generator', GeneratorSchema);

module.exports = Generator


const path = require("path"); const express = require("express"); const dotenv = require("dotenv"); const bodyParser = require("body-parser"); const Generator = require("./models/user");

const connectDB = require("./config/mongodb");

dotenv.config({ path: "./config/config.env" });

connectDB() const app = express();

app.use("/", express.static(path.join(__dirname, "public"))); //Static Folder

app.use(bodyParser.json()); app.use(cors());

const PORT = process.env.PORT || 3001;

app.listen(PORT, () => console.log(Server is running on ${process.env.NODE_ENV} mode on port ${PORT}) );

2 Answers

Your answer