TheAPIProject is a versatile and affordable API platform designed to provide developers with easy access to a diverse range of services. Initially conceived as a "Random Quote Generator API" the project is expanding its vision to encompass a rich collection of data services. Upcoming releases include GIFs, Dummy or Mock APIs for testing, Jokes, and more. With a focus on affordability and simplicity, TheAPIProject stands as the go-to solution for developers seeking dynamic content.
For the corresponding frontend, visit the The API Project Frontend.
- Public API
- Users API
- Quotes API
- Giphies API
- OCR API
- Session Middleware
- Database Management using Sequelize ORM
Note: Find all API-related configurations in src/config/
, such as src/config/subscriptionConfig.js
, src/config/ocrOptions.js
, etc.
Explore the API documentation API Documentation and Postman Workspace.
Before you begin, ensure you have met the following requirements:
- Node.js installed (https://nodejs.org/)
- PostgreSQL installed and running
- Git (optional, but recommended)
- Express.js
- PostgreSQL
- Sequelize ORM (for database)
- ESLint (for code linting)
- Session-based Authentication (for Users)
- JWT Authentication (for API Access Keys)
Before starting the local server, make sure you have PostgreSQL Server installed and running.
If you're a developer making modifications to the project, refer to the Database Management with Sequelize ORM
section for detailed information on creating the database, migrations, and seeders.
-
Clone the repository:
git clone https://github.com/HamidByte/The-API-Project.git
-
Install dependencies:
cd The-API-Project npm install
-
Configure Environment Variables:
Create
.env.development
and.env.production
files in the root of the project for the development and production environments, respectively and set the following variables in each file:.env.development:
SESSION_SECRET_KEY=your-secret-key API_SECRET_KEY=your-secret-key # Email EMAIL_ADDRESS=your-email-address EMAIL_PASSWORD=your-email-password DATABASE_URL=postgres://USERNAME:PASSWORD@localhost:5432/DATABASE_NAME # Client url BASE_URL_CLIENT=http://127.0.0.1:5173 # Server environmental variables (optional) HOST=127.0.0.1 PORT=3000 BASE_URL_SERVER=http://127.0.0.1:3000
.env.production:
SESSION_SECRET_KEY=your-secret-key API_SECRET_KEY=your-secret-key DATABASE_URL=database-url # Email EMAIL_ADDRESS=your-email-address EMAIL_PASSWORD=your-email-password # Client url BASE_URL_CLIENT=your-client-url # Server environmental variables (optional) HOST=your-host-name PORT=your-port-number BASE_URL_SERVER=your-base-url-server
- A database URL is required. Update
USERNAME
,PASSWORD
, andDATABASE_NAME
in the.env.development
file to configure the database for development. - If you intend to use a cloud database, it's pre-configured for production in the
.env.production
file. Ensure theDATABASE_URL
is properly set up for production environments. - To customize the database configuration, modify the
src/config/dbConfig.js
file as needed, supporting both development and production environments. Ensure SSL is enabled for production by settingssl: true
in the production configuration. - Certain email services may block SMTP access. For Gmail, generate a Google app password, enabling the
less secure apps access
account setting in your Google account. - Note that this setting is turned off by default, and you need to enable it.
- If you are using another email service provider that supports SMTP, update the settings in
src/config/emailConfig.js
.
- A database URL is required. Update
-
Configure the Database Settings:
Create a database in PostgreSQL Server. Open
src/config/dbConfig.js
and update the fields below with your PostgreSQL database details:"development": { "username": "your_username", "password": "your_password", "database": "your_database_name", "host": "your_database_host", "port": 5432, "dialect": "postgres" },
- The default port for PostgreSQL is 5432.
- Set the
dialect
topostgres
for PostgreSQL. - (optional) Use the
.data/database/database.sql
file to import the provided database, if available.
-
Start the server:
For development:
npm start
or
npm run dev
The server is now running at http://127.0.0.1:3000
For production:
npm run prod
npm install pm2 -g
npm run pm2
More useful PM2 Commands:
pm2 monit
pm2 save && pm2 startup
We express our gratitude to the open-source community for their invaluable contributions, which have played a pivotal role in enhancing our project by providing essential tools and libraries.