AsyncAPI Node.js
Code Generator
Use your AsyncAPI definition to
generate the code for your API.
The generated code features:
- Default Node.js template, featuring:
- ES7
- ESLint
- YAML config file
- Hermes
- No transpiling
- Custom templates. Check
--templates
option in the Usage section. Kudos to @jantoniucci.
Install
To use it from the CLI:
npm install -g asyncapi-node-codegen
To use it as a module in your project:
npm install --save asyncapi-node-codegen
Usage
From the command-line interface (CLI)
Usage: anc [options] <asyncAPI> Options: -V, --version output the version number -o, --output <outputDir> directory where to put the generated files -t, --templates <templateDir> directory where templates are located -h, --help output usage information
Examples
The shortest possible syntax:
anc asyncapi.yaml
Specify where to put the generated code:
anc asyncapi.yaml -o ./my-api
Specify where to find the code templates:
anc asyncapi.yaml -t ../my-specific-templates-dir -o ./my-api
As a module in your project
const path = ;const codegen = ;const asyncapi = '/path/to/asyncapi.yaml'; // Or a path to a JSON file codegen;
Using async/await
The function codegen.process
returns a Promise, so it means you can use async/await:
const path = ;const codegen = ;const asyncapi = '/path/to/asyncapi.yaml'; // Or a path to a JSON file try await codegen; console; catch err console;
Author
Fran Méndez (@fmvilas)