This is an implementation of Todo-Backend.
How the code works
This codebase uses app-context to boot and initialize the application.
This is managed by the
app-context.js file. It uses a few community-based initializers to read
and environment-specific config file, connects to the MongoDB endpoint in the configuration, and then
creates and starts an express server. You might notice that babel
is being used in this project but never referenced explicitly. This is because
.babelrc file and automatically load babel into your project.
The express initializer will create a new server
and add a default set of middleware to it (check the docs), then it will pass the server to the
file to add routes.
We configure the server with a set of routes using a resolver that will lazy-load modules as they are
needed by the router. This resolver expects to find a class that it will lazily instantiate. It will
then call the methods passed to the
resolve calls, expecting a promise. It will take the response and
encode it as JSON. The
resolve.errorHandler at the end of the file will catch errors thrown through
promises in the resolved handlers, encoding them properly as JSON and setting the status code correctly.
The Todo routes are handled in
routes/todos.js (referenced by the resolver). Here we grab a model from
MongoDB (which uses promises) and use it to do some basic CRUD operations. Thanks to a lot of beautiful
methods even shorter we use
@view from @mattinsler/garnish
to transform the returned records before they're sent to the client.
If you want any help or just want to tell me how horrible my code is, please reach out to me!