
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
totoro-node
Advanced tools
Totoro is a Node.js module to help simplify route management and reduce code duplication for multiple API versions. Totoro will keep you dry!
This module allows you to easily define multiple API versions which can inherit endpoints from previous versions or override the functionality of an endpoint in a subsequent version of the API.
Totoro uses express to create a router with all the routes you define in the API version definition. It returns a router with routes to each of your defined endpoints that can be easily modified, deprecated or disabled as your API changes and grows over time.
npm install totoro-node
or add a dependency to your package.json
"totoro-node": "<version>"
The following syntax can be used:
app.use(path, totoro.rain(configuration, loggerInstance, clearConsole));
Where,
path is the base path for the router returned by totoro.rain().configuration is the router configuration, as described below.loggerInstance is a custom logger instance.clearConsole boolean; if true, console will be cleared whenever rain() is called. Defaults to false.var express = require('express');
var app = express();
var totoro = require('totoro-node');
app.use('/api', totoro.rain({
v1: { // this is an API version definition
active: true, // this parameter are optional but the default value is true when not specified
deprecated: false, // this parameter are optional but the default value is false when not specified
endpoints: [
{
route: "/test/endpoint",
method: "GET",
middleware: [myMiddlewareFunctionOne, myMiddlewareFunctionTwo],
active: true, // this parameter are optional but the default value is true when not specified
deprecated: false, // this parameter are optional but the default value is false when not specified
implementation: originalImplementationFunction
},
{
route: "/another/test/endpoint",
method: "POST",
implementation: anotherImplementationFunction
}
]
},
v2: {
endpoints: [
{
route: "/test/endpoint",
method: "GET",
implementation: overridingOriginalImplementationFunction
}
]
}
}));
This returns a router with the following routes:
/api/v1/test/endpoint
/api/v1/another/test/endpoint
/api/v2/test/endpoint - overrides original implementation from version v1
/api/v2/another/test/endpoint
All the previous endpoints in version v1 are carried over to version v2 but any endpoints that are redefined in v2 will override the original endpoint with the new v2 implementation. This type of inheritance and overriding can be controlled using the active and deprecated fields in the API versioning definition above.
Logging is performed internally using Winston by logging debug messages. Logging can be enabled by passing a reference to the Winston logger when calling the rain function.
Note: Any other logger object that supports logger.log({<level>, <message>}) interface can be passed to loggerInstance.
totoro.rain({<configuration>}, loggerInstance)
The configuration map used in the rain function contains a few fields:
active (optional)
deprecated (optional)
method (required)
middleware (optional)
endpoints (required)
implementation (required)
function(apiVersion, req, res, next) { <endpoint implementation> } This is based on the express functions get, post, delete and put each of which require req, res and next parameters.
apiVersion
v1 and v2 respectively. This can be used in your endpoint implementation function to decide which version of the endpoint is being called. If you choose to reuse the same implementation function across multiple versions but want to make a minor change for one specific version of the endpoint then this will help avoid the need to create another implementation function.req
res
next
If you have any suggestions or encounter any problems using this module then feel free to open an issue on GitHub.
Contributions are welcome.
Thank you for reading :)
FAQs
Route Management for API Versioning
The npm package totoro-node receives a total of 84 weekly downloads. As such, totoro-node popularity was classified as not popular.
We found that totoro-node demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.