Messenger bot using Botkit on AWS: "bodyParser is not defined" error - node.js

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"
}

Related

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.

Azure Error: SSL Error: CERT_UNTRUSTED when using mongoose

Have a locally running node.js app using mongoose to do crud with mlab's mongodb. No problems
I post my code to github, and then tell Azure to host my app as a webapp, which I have done many times without mongoose.
As best I can tell, Azure does an npm install on my package.json file on my behalf as it installs my app into one of their web server hosts.
If I comment out these lines in my users.js route:
//var mongoose = require('mongoose');
//var ObjectID = require('mongodb').ObjectID;
all is well, Azure runs my app.
If I do not comment them out, I get this error written in the Azure log:
npm http GET https://registry.npmjs.org/mongoose
npm ERR! Error: SSL Error: CERT_UNTRUSTED
In an effort to fix this in my package.json file, I have:
[1] forced azure to use this version of node
"engines": {
"node": "0.8.x"
},
[2] tried to force to a current version
"mongoose": "^5.3.11",
[3] tried to force negotiator to this version as GitHub was complaining about a security issue with negotiator
"negotiator": ">=0.6.1",
I would REALLY like to continue to have Azure run my web apps using GitHub, and not get into the Azure command line stuff to install my bits, so I don't have much control of the installation. There is something about Mongoose that is bad.
thanks
One thing you could try is updating to the newer certificates' definitions.
This version of config-defs.js might do the trick (usually located under /deps/npm/lib/utils).
You might also need to update that file with an additional certificate as described here
Hope it helps!
Neil Lunn fixed it, thanks. I was having problems running v10.x.x of node, and tried dropping back to V8.x.x to get around a breaking change in v10, and I screwed up the name of V8. "node": "0.8.x" does not get V8, 8.10.0 does and all is well.

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

SwaggerUI + NodeJs (Meteor)

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?

Nodemailer: require is not defined

I have a problem using Nodemailer. These are the instructions I follow: http://www.nodemailer.com/docs/install
I'm using Grunt server.
Step 1
I start writing this command inside my project folder:
npm install nodemailer --save
And everything seems to be working, the nodemailer folder appears inside node_modules folder and inside package.json I have this line of code:
"dependencies": {
"nodemailer": "^0.6.3"
},
Step 2
I try to reference to the nodemailer by writing this inside my javascript file:
var nodemailer = require("nodemailer");
Error
But then I get this error: Uncaught ReferenceError: require is not defined
Other methods
I have also tryed to do the following:
require("nodemailer.js");
require("/..path.../nodemailer.js");
But nothing seems to work.
Have anyone any idea why I can't access nodemailer? Please keep in mind that I'm new to javascript. Thank you :)

Resources