-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (27 loc) · 878 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const express = require('express') ;
const app = express() ;
const Mongoose = require("mongoose");
const BodyParser = require("body-parser");
Mongoose.connect("mongodb://result:ipusem3@ds211029.mlab.com:11029/ipresults") ;
var studentSchema = new Mongoose.Schema({
rollNo: String,
name: String,
results: { type: [{
subject: String,
marks: String
}] }
});
const studentModel = Mongoose.model("student", studentSchema);
app.use(BodyParser.json());
app.use(BodyParser.urlencoded({ extended: true }));
app.get("/students", async (request, response) => {
try {
var result = await studentModel.find().exec();
response.send(result);
} catch (error) {
response.status(500).send(error);
}
});
app.listen( process.env.PORT || 8080, function(data) {
console.log(data + "App is running at localhost:8080") ;
}) ;