A Restful API built using NodeJS and MongoDB
- About
- Presentation & Examples
This api uses NodeJS version 16.14.2, MongoDB version 6.0.3 and some other dependencies the versions of which are :
dotenv : "^16.0.3",
express : "^4.18.2",
mongoose : "^6.8.3",
nodemon : "^2.0.20"
First, open the project on Visual Studio Code. Once it did, then go to terminal and type :
npm install
Since the project uses MongoDB as the database, we need to download and install it locally. Here is the link below :
mongodb-windows-x86_64-6.0.3-signed.msi
Note : Leave checked the option "Install MongoDBCompass" and after the installation precise the MongoDB bin folder in your PATH environment variable. To ensure MongoDB was successfully installed, go to your command prompt and type these commands :
mongod --version
mongo
If the mongo command does not work, it means you need to install MongoDB Shell. Here is the link :
Note : Just paste the command given on the site in your Windows command prompt or cmd
After installing the project dependencies and MongoDB, we now need to create the database and the collection that will be using. To do so, follow these commands :
// Open MongoDBCompass, go to >_MONGOSH and get the existing databases
show dbs
// Implicitly create the student database
use student
// Verify that the student's database was really created and that you are on
db
To launch the server, just go back to your Visual Studio Code then on terminal and type the following command :
npm start
In order to enhance to this project, just make a contribution by doing a pull request. It'll be a great pleasure to receive it.
After following the instructions above, the project structure may look like this :
Get all the students in the student's database
Add a student in the student's database