This app serves REST API using NodeJS and uses MongoDB
So this REST API, servers two contexts,
GET - /quotegenerator: Chooses a random quote from the database.
POST - /quotegenerator : Lets user add a new quote using quote, author as main fields.
Important libraries to import are:
Nodemon: nodmon will help us to keep track of changes to our application by watching changed files and automatically restart the server.
npm install --save-dev nodemon
NOTE: Once nodemon is installed, you will have to add the following line manually into the package.json file, under scripts(if already not there):
"start": "nodemon server.js"
Express: express will be used to create the server
npm install express --save
Mongoose: Mongoose is what we will use to interact with a MongoDB(Database) instance.
npm install mongoose --save
Mongoose Random: Used to choose the random document from the chosen mongoose collection.
npm install mongoose-random
Below are some details, change as per your need:
Mongo Database Name used: quoteGeneratorDB
Collection Name: quotes
Collection structure: quote(String), author(String), quotetype(enum['love', 'inspirational', 'patriotic'])
Here is a link to the next project that I made building up on this knowledge.