Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
express-api-docs
Advanced tools
A simple wrapper for generating REST API documentation for Express-based projects. This combines the parsing of [dox][1] with a [Handlebars][2] template engine to produce HTML documentation describing a REST interface.
Keep in mind, the project makes some assumptions, so you probably want to really just clone this project and change it.
You can install by either running the following command:
npm install express-api-docs
Or adding the appropriate line to your package.json
file.
Create a JavaScript file, like make-docs.sh
that contains the
following:
var api = require('express-api-docs');
api.generate('app.js', 'public/api.html');
The api
variable has a single function, generate()
, which
takes two parameters:
app
or router
script (see below).Currently, the project reads a single file for all the routes. While most
projects use the app.js
file, you could separate the routes into another file
that the app.js
file calls. Something like a router.js
file:
/**
* Routes all API requests to particular functions.
* This file would be referenced by the `app.js` file, as:
*
* var app = express.createServer();
* var routes = require('./router');
*
* And called:
*
* routes.setup(app);
*/
var index = require('./routes/index');
var user = require('./routes/user');
module.exports.setup = function( app ) {
app.get( '/', index.index );
app.get( '/user', user.getAllUsers);
app.post( '/user', user.createUser);
app.get( '/user/:email', user.getUser );
app.delete('/user/:email', user.deleteUser);
app.put( '/user/:email', user.updateUser );
};
The parsing code for analyzing the routes is currently very brittle and will be the first piece to be retooled.
The documentation also reads Express-Resource entries. For instance:
app.resource('user', require('./resources/user'));
app.resource('register', require('./resources/register'));
app.resource('apps', require('./resources/application'));
app.resource('services', require('./resources/service'));
In this case, the files are read and the REST routes are determined based on the name of the function:
GET /name
-> index()
GET /name/new
-> new()
POST /name
-> create()
GET /name/<ID>
-> show()
GET /name/<ID>/edit
-> edit()
PUT /name/<ID>
-> update()
DELETE /name/<ID>
-> destroy()
Bug Fix: Variable names that require other files now can include underbar characters.
Work with both Express routes (e.g. app.get
) as well as
Express Resource projects (e.g. app.resource
).
Minor Update: Templates now use the Handlebars project.
Initial project that can parse a given JavaScript file containing Express
routes, e.g. app.get
and app.post
, and infer the comments from the
referenced files.
FAQs
Generates an API document from code built with Express
We found that express-api-docs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.