Welcome to the Technology Templates Node.js Rest API repository!
This API handles all <<feature_a>> and its related <<features_b>>
To get started, follow these steps:
-
Install Required Dependencies:
This project requires Docker installed and running since uses local PostgresSQL databases and Wiremock
-
Install Project Dependencies:
npm install
You can launch this application locally by executing:
-
launch local dependencies & mocks
npm run compose:up
-
create required databases and schemas
npm run migrate
-
finally start application
npm run start
All existing tests are located in the test folder. You can execute them by running:
npm run test
The first time you bring this application to production you must pre-create some database users:
-
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
-
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.
-
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
-
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;
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.
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