npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node2-blockly

v2022.10220.2000

Published

A lowcode blockly editor for your API / swagger / OpenAPI

Downloads

21

Readme

Node2-blockly

This package shows you your API in a blockly-like way.

To use it

npm i node2-blockly

Example with Express

Then you can use it like this:

var express = require('express');
var app = express();

function swaggerDocs(app, port) {
  app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
  app.get('/docs.json', (req, res) => {
      res.setHeader('Content-Type', 'application/json');
      res.send(swaggerSpec);
  })
}

swaggerDocs(app, 3000);
//code with API
var dirBlockly= path.join(__dirname , 'node_modules','node2-blockly','docs');
console.log('blockly folder',dirBlockly);
app.use("/BlocklyAutomation", express.static(dirBlockly));
// catch 404 and forward to error handler
app.use(function(req, res, next) {
  console.log('404',req.path);
  if(req.path.startsWith("/BlocklyAutomation")){
    console.log('test');
    res.sendFile(path.join(dirBlockly, 'index.html'));
    return;
  }
  next(createError(404));
});


Full working example at https://github.com/ignatandrei/BlocklyAutomation/tree/main/src/examples/expressExample

Example with NestJS

Then you can use it like this:

var dirBlockly=__dirname + '/../node_modules/node2-blockly/docs/';
console.log('blockly is at '+ dirBlockly);
app.use('/blocklyAutomation',express.static(dirBlockly));
app.use('/blocklyAutomation/*',express.static(dirBlockly));

Of course , you should have also the swagger package installed.

const options = new DocumentBuilder()
    .setTitle('NestJS API')
    .setDescription('NestJS API description')
    .setVersion('0.1.0')
    .build();
const document = SwaggerModule.createDocument(app, options);

SwaggerModule.setup('api', app, document);

Full working example at https://github.com/ignatandrei/BlocklyAutomation/tree/main/src/examples/nestjs-swagger-ui-express

Example with koa

Then you can use it like this:

const app = new Koa();

app
  .use(cors())
  
  .use(async (ctx, next) => {
    if(ctx.path.startsWith('/BlocklyAutomation') ) {
      var folder=path.join("node_modules", 'node2-blockly','docs');// "tet";
      console.log('root for blockly '+folder);
      if(ctx.path === '/BlocklyAutomation' || ctx.path === '/BlocklyAutomation/') {
        var file=path.join(folder, 'index.html');
        await send(ctx, file);
        return;
      }
      
      var fileToServe = ctx.path.replace('/BlocklyAutomation','');
      var file = path.join(folder, fileToServe);
      if(fs.existsSync(file)) {
        console.log('serving ' + file);
        await send(ctx, file);
      }
      else{
        //serving index
        var file=path.join(folder, 'index.html');
        await send(ctx, file);
        return;
      }
      return;
    }
    
    await next();
    const rt = ctx.response.get('X-Response-Time');
    console.log(`${ctx.method} ${ctx.url} - ${rt}`);
  })

Of course, you should have koa-swagger-decorator

Full working example at https://github.com/ignatandrei/BlocklyAutomation/tree/main/src/examples/nodeKoa

More details at http://github.com/ignatandrei/BlocklyAutomation