whether feathers js client has disconnect function? - feathersjs

I am using feathers + primus to communicate with feathers server. Below is the client code to initialise client instance. The connection between client and server will be created on the code .configure(feathers.primus(primus));. I wander whether it has a function to disconnect the connection.
const feathers = require('feathers-client');
const rest = require('feathers-rest/client');
const Primus = require('../public/dist/primus.js');
let primus = new Primus('http://localhost:3030');
let app = feathers()
.configure(feathers.hooks())
.configure(feathers.primus(primus));

Related

simple Forge 3-legged Oauth with node.js

I am new to Forge and using node.js - I am having some difficulty getting a simple 3-legged Oauth process to work.
This is how far I have got below. It gives me the error "Cannot GET /api/forge/oauth/callback"
I have checked that my callback url matches what is in the Forge App.
Ultimately what I am trying to achieve is, getting the shared link for a newly created file in Fusion teams, or at least opening the browser to the file overview page.
Would anybody be able to help with this?
var express = require('express');
var ForgeSDK = require('forge-apis');
const { stringify } = require('node:querystring');
var opn = require('opn');
// Set up Express web server
var app = express();
// Set the Forge Variables
var FORGE_CLIENT_ID = 'client-id', FORGE_CLIENT_SECRET = 'client-secret', REDIRECT_URL = 'http://localhost:3000/api/forge/oauth/callback';
// This is for web server to start listening to port 3000
app.set('port', 3000);
var server = app.listen(app.get('port'), function () {
console.log('Server listening on port ' + server.address().port);
});
// Initialize the 3-legged OAuth2 client, set specific scopes and optionally set the `autoRefresh` parameter to true
// if you want the token to auto refresh
var autoRefresh = true;
var oAuth2ThreeLegged = new ForgeSDK.AuthClientThreeLegged(FORGE_CLIENT_ID, FORGE_CLIENT_SECRET, REDIRECT_URL, [
'data:read',
'data:write'
], autoRefresh);
// Generate a URL page that asks for permissions for the specified scopes.
var AuthURL = oAuth2ThreeLegged.generateAuthUrl();
console.log(AuthURL)
opn('https://developer.api.autodesk.com/authentication/v1/authorize?response_type=code&client_id=<<client-id>>&redirect_uri=http://localhost:3000/api/forge/oauth/callback&scope=data:read+data:write&state=undefined', {app: 'chrome'})
where is the callback API in your code?
BTW 3-Legged oauth is implemented here in nodejs, you can use it as reference:
https://learnforge.autodesk.io/#/oauth/3legged/nodejs

JDBC not connecting on Google Apps Script

I'm trying to connect to my MySQL server in Google Apps Script. I am able to connect through MySQL Workbench from my PC and with MySQL from another server, I tested permissions, I can insert and other stuff.
This is the code I have in Apps Script:
function myFunction() {
var server = "zikovi.eu";
var port = 3306;
var username = "test";
var database = "testdb";
var password = "testpwd";
var url = "jdbc:mysql://"+server+":"+port+"/"+database;
Logger.log(url);
var conn = Jdbc.getConnection(url, username, password);
No matter what, the error says to check the URL, username or password. The parameters are correct (you can check, it's a test user and db).

Connection issue with API when using JSON data only in Postman

I'm trying to setup a simple login API using node.js/restify. The code below shows a simple route, with nothing but a console.log() statement within it, as I'm just trying to prove I can gain a connection.
var restify = require('restify');
var user = require('./user');
var reference = require('./reference');
var fs = require('fs');
var bodyParser = require('body-parser');
var _= require('lodash');
const server = restify.createServer();
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({extended:false}));
server.use(restify.plugins.fullResponse())
server.use(restify.plugins.bodyParser());
server.use(restify.plugins.queryParser()) server.use(restify.plugins.authorizationParser())
var port = 8080;
server.post('/user/login', (req, res) => {
console.log("---LOGIN ATTEMPT---");
res.status(200);
res.end();
});
Using Postman for testing, I expect to get a statement back in the console, stating "LOGIN ATTEMPT".
Postman freezes with the 'Loading' text and stays like that until it crashes saying 'There was an error connecting to localhost:8080/user/login'. This only occurs when sending JSON data and not when sending form-data, which is where my confusion is occurring. It is acting as if an infinite loop is occurring with JSON data but can not trace where it is happening.
because you are not sending any data back to requesting browser(in this case postman) try returning some response as body
for example use res.send('success')

Google Cloud Functions: require(...) is not a function

I am trying to deploy a Google Cloud function, I started by just adding the initial requirements to my index.js file:
// Import the Google Cloud client libraries
const nl = require('#google-cloud/language')();
const speech = require('#google-cloud/speech')();
const storage = require('#google-cloud/storage')();
But I get the following message when deploying:
Detailed stack trace: TypeError: require(...) is not a function
This only happens with the #google-cloud/speech and #google-cloud/language modules, the #google-cloud/storage module is loaded fine as a function (I tested by commenting the first two).
Any advise will be greatly appreciated.
Borrigan
With reference to this Github comment, there was some changes in google-cloud v2 package
so you import packages such as:
const {Storage} = require('#google-cloud/storage');
const storage = new Storage({
// config...
});
Google cloud function are nodejs modules so the syntax is same as nodejs syntax.
Regarding your problem:
you have to write
const storage = require('#google-cloud/storage');
(without () at the end of each statement)
So the correct declaration will be:
// Import the Google Cloud client libraries
const nl = require('#google-cloud/language');
const speech = require('#google-cloud/speech');
const storage = require('#google-cloud/storage');
I hope this helps.
It tells you that whatever you required is not a function and therefore can't be invoked with ()
if you look here : https://www.npmjs.com/package/#google-cloud/language#using-the-client-library
you see a service object with multiple class returning functions is being returned, so you should set it up like this:
const nl = require('#google-cloud/language');
const language = new nl.LanguageServiceClient();
Follow the new syntax below:
const {Storage} = require('#google-cloud/storage');
const googleCloudStorage = new Storage({
projectId: 'your-project-id',
keyFilename: 'path-to-json-config-file'
});

how to publish realtime streaming json data received from a URL over mqtt using node.js

I have the following code which accepts data from the url and print the json formatted data.I want to publish the same data to mqtt using node.js.Is there any sample code for the same?
`var request = require('request')
var JSONStream = require('JSONStream')
`var es = require('event-stream')`
`request({url: 'http://isaacs.couchone.com/registry/_all_docs'})
`.pipe(JSONStream.parse('rows.*'))
.pipe(es.mapSync(function (data) {
console.log(data);
console.error(data)
return data
}))
You could use the mqtt node library MQTT.js
Your current code becomes something like that:
var request = require('request');
var JSONStream = require('JSONStream');
var es = require('event-stream');
var mqtt = require('mqtt');
request({url: 'http://isaacs.couchone.com/registry/_all_docs'})
.pipe(JSONStream.parse('rows.*'))
.pipe(es.mapSync(function (data) {
console.log(data);
console.error(data);
//MQTT publish starts here
var client = mqtt.createClient(1883, 'localhost');
client.publish('demoTopic', JSON.stringify(data));
client.end();
return data;
}))
The above code assumes the broker is running on the local machine on port 1883.
Just use a node.js library for mqtt such as MQTT.js https://github.com/adamvr/MQTT.js
Also you can run your own multi-protocol broker in node.js by installing mosca https://github.com/mcollina/mosca