REST JSON API for sssnap
npm install
- MongoDB installed and running
After running npm start
the server is accessible on https://localhost:3000
.
The API is versioned to avoid problems with an updated API and a not-updated client. The version number is the first part of the URL path and takes the form X.Y, whereas the trailing zero is omitted.
Examples: https://localhost:3000/1/
, https://localhost:3000/1.1/
-
server.js
Base setup of the application. Initialize the database, express and the server here. -
config/
Configuration of modules and other key-value based configurations. -
routes/
The versioned routes, which will redirect to the appropriate controller. -
controllers/
Controllers – are connected with the routes.
To be always and everywhere up-to-date with the database schema, the models are a separate node module and can be found in 51seven/sssnap-models. You can work with them like normal mongoose models.
var User = require('sssnap-models').Users;
Users.findOne({ email: '[email protected] '}, function (err, user) {
...
});
There's a global Logging-Method accessible in all files. It's the winston logger with a predefined console output.
-
Log.d()
Log on debug level -
Log.v()
Log on verbose level -
Log.i()
Log on info level -
Log.w()
Log on warn level -
Log.e()
Log on error level
The Console output will log all levels with a timestamp and a color for each level.