Skip to main content

Get started with LibAPI

Start with cloned repository

To get started with the API, if you have cloned the repository, navigate to the api directory:

cd api

and run the command:

 npm install

to install the necessary dependencies. Then, start the server by running:

 npm start

Make your own project

If you haven't cloned the repository and/or you don't have required tools installed, you will need to first install MongoDB and Mongosh from the official site and add the MongoDB bin folder path to the PATH environment variable if you host the database locally. Next, you will need to install npm and add it to the PATH environment variable.

After that, run the command to initialize a new Node.js project:

 npm init

Then install the following dependencies using the:

 npm install

Dependencies

Packages needed:

  • cors,
  • dotenv,
  • express,
  • jsonwebtoken (for authentication),
  • bcryptjs (for encryption),
  • mongoose (to connect to MongoDB),
  • nodemon (to automatically restart the server).

You will also need to create a config folder with an auth.config.js file. This file should export an object containing a secret property (which should be set to your secret), a tokenExpiration property (set to the desired token expiration time in seconds), and a refreshExpiration property (set to the desired refresh token expiration time in seconds).

If you haven't already done so, create a .env file and add a line with the following:

DATABASE_URL=`your MongoDB link after creating a database on MongoDB.com or local one using username and password authentication`

Start your project

Finally, to start the server, run the command:

npx nodemon index.js 

This will automatically restart the server whenever changes are made to the code.