SwaggerUI + NodeJs (Meteor) - node.js

I have a meteor app with a REST API by https://atmospherejs.com/simple/json-routes.
Now I want to document my API with SwaggerUI. I already used SwaggerUI in other projects and know you have to create a yaml or json sepc file, which then is being displayed by SwaggerUI.
So now I have discovered there are some existing swagger-ui packages for npm:
https://www.npmjs.com/package/swagger-ui
https://www.npmjs.com/package/swagger-ui-dist
which I installed by meteor npm install swagger-ui-dist --save-dev
But I have no clue what to do next or how to use them.
I am sure it must be something as simple as:
const swaggerui = require('swagger-ui');
swaggerui.specPath(pathToYaml);
swaggerui.url('/api-docs');
Can anyone help me with the first steps?

Related

hardhat dependency not picked up by heroku/vercel

I built a Minting API using hardhat. I want to host it on heroku/vercel.
However I get the below error on deployment.
Error: Cannot find module 'hardhat'
I am using node.js, express.js
I have the below require.
const hre = require("hardhat");
My code works perfectly fine on localhost.
Do check if the 'hardhat' is under devDep or dep. It should be under dep in package.json.

NodeJs to Typescript

I need to use nodejs library in my angular project but got example code in nodejs. I have installed library through npm command and import to my component. But it always show undefined.
npm install phenix-edge-auth --save
const TokenBuilder = require('phenix-edge-auth');
// Create a token to access a channel
const token = new TokenBuilder()
.withApplicationId('my-application-id')
.withSecret('my-secret')
.expiresInSeconds(3600)
.forChannel('us-northeast#my-application-id#my-channel.1345')
.build();
How to use this code with angular app?
Import it as angular way..
import * as TokenBuilder from 'phenix-edge-auth'

Nestjs server does not serve socket.io client

I have a split app using nestjs on the server and an Angular app as the client. Setting up websockets with socket.io seemed pretty easy using the #nestjs/websockets module and on the client I used ngx-socket-io. I used this repo as basis. Now when I update the project's #nestjs/websockets dependency to the latest version I get
CORS errors and
an error that the client couldn't load the socket.io client js file
I expected CORS problems and after the update, I could fix them by adding
app.enableCors({
origin: 'http://localhost:4200',
credentials: true,
});
to my main.ts file, but I don't know why the client file is not served. With the version of the repo (5.7.x) there are neither CORS errors nor problems with serving the file.
I tried a couple of settings of #WebSocketGateway(), moving to a different port, setting serveClient (even though it should be true by default), but nothing seemed to work. Any advice?
thanks
In my case
I replaced
app.useWebSocketAdapter(new WsAdapter(app));
from
import { WsAdapter } from '#nestjs/platform-ws';
with
app.useWebSocketAdapter(new IoAdapter(app));
in main .ts from
import { IoAdapter } from '#nestjs/platform-socket.io';
Worked like a charm!
The problem was that nestjs did separate the lower level platform (socket.io, express, fastify, ...) from the nestjs modules. The websocket module requires to install an underlying platform, for socket.io
npm install --save #nestjs/platform-socket.io
To serve the socket.io client file it seems like there also needs to be an HTTP platform installed, for express
npm install --save #nestjs/platform-express
More info in the migration guide for v6.
I had the same problem. i was opening the client side of the application in the web-browser, but directly from my filesystem (i would double click on the file index.html next to the little dummy fake-front-end.js on my desktop for example...). It seems that the CORS problem would persist until i actually accessed the index.html through a proper server. So i created a route on my backend, to serve the index.html, and the fake-front-end.js.
There is a section about CORS on the socket.io officual documentation. And there is a section on the nestjs website, but both didnt really helped in my case.

Nodejs swagger integration - Express Router

I am aware of configuring swagger to my NodeJs project using JSON / YAML. Is there any way to automate the documentation like swagger doing for spring webservices.
Note: I am using Express Router to create endpoints.
Yes, the package swagger-autogen performs the automatic construction of the Swagger documentation.
First, install the package with: npm i swagger-autogen
If you have a endpoint/route file like this:
routes.js
const express = require('express')
const ToolsController = require('./controllers/ToolsController')
const router = express.Router()
const apiV1 = require('./controllers/ApiRoute1')
router.use('/v1', apiV1)
module.exports = router
Just declare a file called swagger.js, for example, with this:
swagger.js
const swaggerAutogen = require('swagger-autogen')()
swaggerAutogen('./swagger-output.json', ['./routes.js']);
In the package.json, add a script such as:
"scripts": {
"swagger-autogen": "node ./swagger.js"
}
And run: npm run swagger-autogen
The Swagger documentation will be in the swagger-output.json.
To add descriptions, tags, summary, and so on, access the https://www.npmjs.com/package/swagger-autogen#endpoints
Examples: Links to projects that cover the simplest use of this module as well as the most complete use. See the links below:
Example using Router
Example without Router
yes, you could use swagger-ui-express or other npm libraries =)
You can use jsdoc. For this you need to install npm packages
npm i swagger-jsdoc
npm I swagger-ui-express
Please refer
node js swagger with express server

Messenger bot using Botkit on AWS: "bodyParser is not defined" error

I set up a Bitnami Node.JS instance on AWS. Installed default Botkit. Updated dependencies. Set up a basic Facebook page/app with Messenger integration. Attempted to run the default Messenger bot example (Facebook_bot.js).
Running the bot gets the following error on load:
ReferenceError: bodyParser is not defined
Since this is all out of the box and using the example Messenger bot, is this an issue with BotKit source? Or have I somehow managed to mess up the minimal setup involved here?
this can mean 1 of 3 things
the node.js file usually named index.js does not have var bodyParser = require('body-parser') less likely
you do not have body-parser installed from npm to do so in command line run npm i body-parser --save
if this is a remote solution and AWS builds based off of package.json add the dependency
"dependencies": {
"body-parser": "^1.17.2"
}

Resources