Giter Club home page Giter Club logo

nodejs-template's Introduction


AsyncAPI logo
AsyncAPI Node.js Template

npm npm

Overview

This template generates a Node.js application with any of the supported protocols endpoint, based on Hermesjs.

Other files are for the setup of developer environment, like .editorconfig or .eslint.

Technical requirements

Specification requirements

Property name Reason Fallback Default
operationId Operation ID must be set for every operation to generate proper functions as there is no fallback in place - -

Supported protocols

How to use the template

This template must be used with the AsyncAPI Generator. You can find all available options here.

In case you use X509 security and need to provide certificates, either place them in the root of the generated server with the following names: ca.pem, service.cert, service.key. You can provide a custom directory where cert files are located using certFilesDir parameter like -p certFilesDir=../not/in/my/app/dir.

Since you can have multiple different security schemes, to use the one of X509 type, you need to pass the name of the scheme like this: -p securityScheme=SCHEME_NAME.

You can find a complete tutorial on AsyncAPI Generator using this template here.

CLI

# Install the AsyncAPI Generator
npm install -g @asyncapi/generator

# Run generation
ag https://bit.ly/asyncapi @asyncapi/nodejs-template -o output -p server=production

##
## Start the server 
##

# Go to the generated server
cd output

# Build generated application
npm i

# Start server
# To enable production settings start the server with "NODE_ENV=production npm start"
npm start

##
## Start the client 
##

#for testing your server you can use mqtt client. open a new terminal and install it using:
npm install mqtt -g

#publish an invalid message.
mqtt pub -t 'smartylighting/streetlights/1/0/event/123/lighting/measured' -h 'test.mosquitto.org' -m '{"id": 1, "lumens": "3", "sentAt": "2017-06-07T12:34:32.000Z"}'

#publish a valid message
mqtt pub -t 'smartylighting/streetlights/1/0/event/123/lighting/measured' -h 'test.mosquitto.org' -m '{"id": 1, "lumens": 3, "sentAt": "2017-06-07T12:34:32.000Z"}'

#You should see the sent message in the logs of the previously started server.
#Notice that the server automatically validates incoming messages and logs out validation errors

Template configuration

You can configure this template by passing different parameters in the Generator CLI: -p PARAM1_NAME=PARAM1_VALUE -p PARAM2_NAME=PARAM2_VALUE

Name Description Required Example
server The server you want to use in the code. Yes production
securityScheme Name of the security scheme. Only scheme with X509 and Kafka protocol is supported for now. No 'mySchemeName'
certFilesDir Directory where application certificates are located. This parameter is needed when you use X509 security scheme and your cert files are not located in the root of your application. No ../not/in/my/app/dir

Development

The most straightforward command to use this template is:

ag https://bit.ly/asyncapi @asyncapi/nodejs-template -o output -p server=production

For local development, you need different variations of this command. First of all, you need to know about three important CLI flags:

  • --debug enables the debug mode in Nunjucks engine what makes filters debugging simpler.
  • --watch-template enables a watcher of changes that you make in the template. It regenerates your template whenever it detects a change.
  • --install enforces reinstallation of the template.

There are two ways you can work on template development:

  • Use global Generator and template from your local sources:
    # assumption is that you run this command from the root of your template
    ag https://bit.ly/asyncapi ./ -o output
  • Use Generator from sources and template also from local sources. This approach enables more debugging options with awesome console.log in the Generator sources or even the Parser located in node_modules of the Generator:
    # assumption is that you run this command from the root of your template
    # assumption is that generator sources are cloned on the same level as the template
    ../generator/cli.js https://bit.ly/asyncapi ./ -o output

Contributors

Thanks goes to these wonderful people (emoji key):


Fran MΓ©ndez

πŸ’» πŸ€”

Lukasz Gornicki

πŸš‡ πŸ’»

Khuda Dad Nomani

πŸ“– πŸ’»

This project follows the all-contributors specification. Contributions of any kind welcome!

nodejs-template's People

Contributors

allcontributors[bot] avatar asyncapi-bot avatar bszwarc avatar dependabot[bot] avatar derberg avatar fmvilas avatar jooaodanieel avatar khudadad414 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.