Skip to content

Latest commit

 

History

History
187 lines (128 loc) · 5.76 KB

README.md

File metadata and controls

187 lines (128 loc) · 5.76 KB

The API Project, Node, Express, PostgreSQL, Sequelize ORM, Session, JWT, Subscription, Logger

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.

Frontend Repository

For the corresponding frontend, visit the The API Project Frontend.

Documentation

Note: Find all API-related configurations in src/config/, such as src/config/subscriptionConfig.js, src/config/ocrOptions.js, etc.

API Documentation on Postman

Explore the API documentation API Documentation and Postman Workspace.

Prerequisites

Before you begin, ensure you have met the following requirements:

  • Node.js installed (https://nodejs.org/)
  • PostgreSQL installed and running
  • Git (optional, but recommended)

Project Dependencies

  • Express.js
  • PostgreSQL
  • Sequelize ORM (for database)
  • ESLint (for code linting)
  • Session-based Authentication (for Users)
  • JWT Authentication (for API Access Keys)

Setting Up PostgreSQL Server and Importing Database

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.

Getting Started

  1. Clone the repository:

    git clone https://github.com/HamidByte/The-API-Project.git
  2. Install dependencies:

    cd The-API-Project
    npm install
  3. 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, and DATABASE_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 the DATABASE_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 setting ssl: 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.
  4. 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 to postgres for PostgreSQL.
    • (optional) Use the .data/database/database.sql file to import the provided database, if available.
  5. 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:

    Option 1. Try it

    npm run prod

    Option 2. Run in the background using PM2

    Install PM2 if you don't have it:

    npm install pm2 -g

    Start Server

    npm run pm2

    More useful PM2 Commands:

    If you want to see the current console output

    pm2 monit

    If you want to add it to startup

    pm2 save && pm2 startup

Acknowledgments

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.