-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Prathamesh More
committed
Sep 18, 2019
1 parent
9f2902c
commit 6195fce
Showing
4 changed files
with
590 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const express = require("express"); | ||
const mongoose = require("mongoose"); | ||
const app = express(); | ||
|
||
//Imports | ||
const Quote = require("./models/quote"); | ||
|
||
//Consts | ||
const PORT = 3000; | ||
const URL = "192.168.43.61"; | ||
|
||
//Database connection | ||
mongoose.connect("mongodb://localhost:27017/quotegarden", { useNewUrlParser: true }, (error) => { | ||
if (error) { | ||
console.log("Error"); | ||
} else { | ||
console.log("Successfully connected to database"); | ||
} | ||
}); | ||
|
||
//Simple GET method | ||
app.get("/", (request, response) => { | ||
response.send("Hello from API"); | ||
}) | ||
|
||
//Simple random requests | ||
app.get("/random", async (request, response) => { | ||
|
||
const documentCount = await Quote.estimatedDocumentCount(); | ||
const index = random | ||
|
||
Quote.find({}, (error, quote) => { | ||
if (error) { | ||
console.log("Error"); | ||
} else { | ||
response.json(quote); | ||
} | ||
}) | ||
}) | ||
|
||
//Routes to find as per search | ||
app.get("/:author", (request, response) => { | ||
response.send("All Authors"); | ||
}); | ||
|
||
//Get all quotes | ||
app.get("/all", (request, response) => { | ||
response.send("All Quotes"); | ||
}) | ||
|
||
|
||
//Start server | ||
app.listen(PORT, () => { | ||
console.log("Server running on port : " + PORT) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const mongoose = require("mongoose"); | ||
|
||
//Define schema for quotes | ||
const quoteSchema = new mongoose.Schema({ | ||
content: String, | ||
author: String | ||
}); | ||
|
||
//Create model on the basis of quote schema | ||
const Quote = new mongoose.model("quote", quoteSchema); | ||
|
||
module.exports = Quote; |
Oops, something went wrong.