node-api-sample by The Shop
Application that serves as REST API and is written on top of Node.JS and Express.JS.
Application is event driven and code structure allows easy micro service deployment.
Given the code microservice structure making it event based made sense just because of easier code functionality extending in the future.
All developer has to do is listen to specific event to re-use the logic, without finding
a good place in code to extract the functionality to - place is already there - the src/Listeners/
directory (more
on that below where code structure is explained).
Following services are set up:
- NewRelic
- Crud
- Users
- Posts
- Comments
- Authorization
- Enabled strategies:
- PasswordStrategy
- Enabled strategies:
Documentation is generated from inline Swagger annotations.
Documentation is available at: http://localhost:3030/api-docs/ when API is started.
$ yarn # or `npm install`
$ cp .env.example .env
$ # fill in data in .env
$ yarn start # or `npm run start` for development or
$ yarn start:live # or `npm run start:live` for production
$ yarn database seed # or `npm run database seed` - will create sample dataset
NewRelic
- for monitoringMailgun
- for transactional emailsS3
- for file uploads
Application depends on environment variables, so configure the
environment in .env
file in root of the project with correct
information.
-
admin/
source of React administration -
docs/
documentation on specific topics -
public/
express uses this directory to serve static assets -
src/
main source code for the project-
cron/
directory contains all of cron jobs -
Database/
directory contains seeders and Database class -
Framework/
directory all of the files used to run the application -
Helpers/
directory all of the helper classes used in the project -
Services/
directory contains all of services-
<SERVICE_NAME>
name of the serviceAdapters/
directory contains all of API output adapters for specific serviceCollections/
directory contains all collections that service depends onModels/
directory contains all models that service depends onListeners/
directory contains all service listeners
-
-
Templates/
directory contains custom transactional email templates
-
-
test/
directory contains test files -
tools/
is used for various tasks (such is app startup)
Project also uses Admin on REST React library to provide data administration interface.
You can access it at: http://localhost:3030/admin when API is running.
Both list of all defined (and triggered) events and map of what listener listens to what event can be found in docs/EVENTS.md
.
Explanation on how to implement new listeners can be found in src/Listeners/README.md
.
Each of services can have own events.
Repository is set up with linter and unit tests. Both run on auto-installed pre-commit hook (hook installs on initial node_modules instalation).
To run linter run:
$ yarn lint # or or `npm run lint`
To run unit tests run:
$ yarn unit:test # or `npm run unit:test`
To run all:
$ yarn test # or `npm run test`
Seeders are found in src/Database/seed/
directory.
API documentation (swagger) is auto-generated from annotations in Adapters and Actions.
Events documentation (file: docs/EVENTS.md
) is re-generated on application start.