Skip to content

nullplatform/technology-templates-node-js-rest-api

Repository files navigation

nullplatform

Technology Templates Node.js Rest API

Welcome to the Technology Templates Node.js Rest API repository!

Table of Contents

Introduction

This API handles all <<feature_a>> and its related <<features_b>>

Getting Started

To get started, follow these steps:

  1. Install Required Dependencies:

    This project requires Docker installed and running since uses local PostgresSQL databases and Wiremock

  2. Install Project Dependencies:

    npm install

Development

You can launch this application locally by executing:

  1. launch local dependencies & mocks

    npm run compose:up
  2. create required databases and schemas

    npm run migrate
  3. finally start application

    npm run start

Testing

All existing tests are located in the test folder. You can execute them by running:

npm run test

Production

The first time you bring this application to production you must pre-create some database users:

  1. A migration DB user

    CREATE USER <<your_api_name_here>>_migration WITH ENCRYPTED PASSWORD '<your_password_here>';
    GRANT CREATE ON DATABASE <<your_database_name_here>> TO <<your_api_name_here>>_migration;

    Create a migration scope and modify parameter named DATABASE_PASSWORD for that scope with the password you specified previously for feature_flag_management_migration user

  2. Run migrations

  • Get a valid token with permissions to run migrations using this <<your_api_name_here>>_MIGRATION_API_KEY

  • Run this command replacing <<<token>>> with the actual token generated by using the specified API key

    curl --request GET \
    --url 'https://<<your_migration_scope_domain_here>>.prod.nullapps.io/?option=migrate' \
    --header 'Authorization: Bearer <<<token>>>'
  • You can replace option with these values:

    • migrate: to run pending database migrations
    • undo: to undo last migration
    • undo:all to undo all migrations. Be careful, this will delete the entire database schema.
  1. An application DB user

    CREATE USER <<your_api_name_here>>_runtime WITH ENCRYPTED PASSWORD '<your_password_here>';

    Create a production scope and then create a parameter for this scope named DATABASE_PASSWORD with the password you specified previously for <<your_api_name_here>>_runtime user

  2. Add permissions to <<your_api_name_here>>_runtime user

    GRANT USAGE ON SCHEMA production TO <<your_api_name_here>>_runtime;
    GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA production TO <<your_api_name_here>>_runtime;
    GRANT SELECT, UPDATE ON ALL SEQUENCES IN SCHEMA production TO <<your_api_name_here>>_runtime;

Environments

This project is designed to operate independently, leveraging Docker containers for key dependencies like a local PostgresSQL database and Wiremock for external service simulation.

Explore the config folder to access predefined values for different environments. Customize your environment by setting the NODE_ENV variable to one of the following options: development, production, or test.

For more granular control, modify the configuration values by adjusting the corresponding environment variables. A detailed list of these variables is available here. Ensure that you fine-tune these settings according to your specific needs and preferences.

OpenAPI Specification

This API automatically generates an OpenAPI V3 specification based on validation and serialization schemas.

To generate an OpenAPI specification enable swagger flag in development config:

{
  server: {
    openAPI: {
      enabled: false, // Disable OpenAPI for development
      ...
    }
  },
}

then start the application:

npm run start

and download the specification under the /documentation/yaml URL, by default should be this one

About

Node.js REST API template

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •