I'm trying to connect to a Gremlin server with the JavaScript driver variant.
Up to package version 2.7.0, this is done easily by passing options to Gremlin.createClient() as in this example for Azure Cosmos DB:
const client = Gremlin.createClient(
config.port,
config.endpoint,
{
"session": false,
"ssl": true,
"user": `/dbs/${config.database}/colls/${config.collection}`,
"password": config.primaryKey
}
);
In newer versions of the package I can't get it done. The official docs suggest using gremlin.driver.auth.PlainTextSaslAuthenticator. However, that method seems to be not implemented in the package and returns TypeError: Cannot read property 'PlainTextSaslAuthenticator' of undefined
My test code (same config.js as in the working example):
const gremlin = require("gremlin");
const config = require("./config");
const Graph = gremlin.structure.Graph;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const graph = new Graph();
const authenticator = new gremlin.driver.auth.PlainTextSaslAuthenticator(
`/dbs/${config.database}/colls/${config.collection}`,
config.primaryKey
);
const g = graph.traversal().withRemote(new DriverRemoteConnection(`ws://${config.endpoint}:${config.port}`, { authenticator });
Return:
C:\repos\gremlin-test\index.js:9
const authenticator = new gremlin.driver.auth.PlainTextSaslAuthenticator(
^
TypeError: Cannot read property 'PlainTextSaslAuthenticator' of undefined
at Object.<anonymous> (C:\repos\gremlin-test\index.js:9:47)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
Anyone know a solution to this?
I've not got too much experience with Gremlin.js, but I just downloaded it and have manually searched through all of its files - I can't find any trace of a PlainTextSaslAuthenticator function or its declaration.
This could mean one of two three -
Its function has been (accidentally) removed
It uses a third party package that has been (accidentally) removed
It has not been added to the package yet
Upon a swift Google search, I found this link which seems to show it being added to /lib/driver/auth, but that directory doesn't seem to exist in the package I got through npm install gremlin. Perhaps it is yet to be released?
I would therefore suggest you raise an issue on Github, but it seems that repository you linked doesn't allow for issues to be raised. So perhaps email/contact the author?
EDIT:
Thanks to Stephen for the link - the code hasn't been merged to the package yet. Keep track of it here.
Related
I am fairly new to js & nodejs. So, I tried to use express-jwt to authenticate most of my apis.
However, I want to exempt routes like /login and /register from authentication
Having gone through the documentation of express-jwt, I learnt that there is such a lib called express-unless
So, I mimicked the example to see if I can get it working. Here's code
const unless = require('express-unless');
app
.use(authenticateWithExpressJWT)
.unless({ path: ['/login'] });
authenticateWithExpressJWT is my middleware function which works fine
const jwt = require('express-jwt');
const verifyJwt = jwt({ secret: 'secreyKey', algorithms: ['HS256'] });
module.exports.authenticateWithExpressJWT = verifyJwt;
When I searched for examples on Google or Stackoverflow, it seems others don't seem to have any problem using similar code. However, when I do this, it doesn't even compile. I get this error
app.use(authenticateWithExpressJWT).unless({ path: ['/login'] });
^
TypeError: app.use(...).unless is not a function
at Object.<anonymous> (/home/xyz/programming/node/firstApp/index.js:27:37)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
Can somebody help me figure out what am I doing wrong ?
I have another question : How is that people are able to use unless() method without require('express-unless');?
I get the above mentioned compilation error irrespective of whether I add const unless = require('express-unless'); or not
Note: I understand that I can achieve the same without using express-unless. I am only keen to understand how I can use it.
I personally haven't worked with express-unless, but according to the docs, you should be able to do this, since express-jwt itself supports unless:
const jwt = require('express-jwt');
const verifyJwt = jwt({ secret: 'secreyKey', algorithms: ['HS256'] })
.unless({path: ['/login'] });
module.exports.authenticateWithExpressJWT = verifyJwt;
In your app then just use your middleware:
app.use(authenticateWithExpressJWT)
I normally exempt routes from auth by creating a function like as shown below.
function authJwt() {
return expressjwt({
'secret',
algorithms: ['HS256'],
isRevoked: isRevoked,
}).unless({
path: ['/login'],
});
}
async isRevoked(req, payload, done){
// your code goes here for revoking
}
and then in your entry point (index.js/app.js), import the authJwt and use it in your entire app.
app.use(authJwt())
I am also facing the same issue in think there is a issue with the latest version
so I use the "express-unless": "^1.0.0" .
it works well for me .
use this version of the package i think its quick fix for this issue
"express-unless":"^1.0.0"
Hello and thank you in advance.
This may be a rather simple scenario, however, I am new to Nodejs.
I have a main script which I am calling from javascript using IISNode. Everything has worked great until I decided to rename a dependency file.
Files involved:
embed.js <- main script
dev2.js <- required custom script by embed.js
which reads this json file
fred.json renamed to chartio.json
embed.js code relevant to issue:
var http = require('http');
var jwt = require('jwt-simple');
var dashinfo = require('./dev2');
var ORGANIZATION_SECRET = dashinfo.getkey();
var ORG_ID = dashinfo.getorgid();
dev2.js code relevant to issue:
var mariadb = require('mariadb');
var connectioninfo = require('./chartio.json');
module.exports = {
getkey: function () {
return connectioninfo.connection.apikey;
},
getorgid: function () {
return connectioninfo.connection.orgid;
},
and finally, I have my charti0.json file which I cannot post due to sensitive data.
I assure you that everything was working until I renamed fred.json to chartio.json.
I have looked online to see if there is a way to clear the cache but I couldn't find anything that seemed to work, though I am a novice. I also looked at logs. I tried running this in IE and Chrome
This is what I see logged from the error:
Application has thrown an uncaught exception and is terminated:
Error: Cannot find module './fred.json'
Require stack:
- C:\xxx\xxx\GPS411\node\dev2.js
- C:\xxx\xxx\GPS411\node\embed.js
- C:\Program Files (x86)\iisnode\interceptor.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:\Omnitracs\sylectus-trunk\GPS411\node\dev2.js:3:22)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:849:19)
Folks, I was able to get this working by doing an old fashion workstation reboot. I changed the filename again to test if the issue returns and it seems to recognize the file changes now. I guess I was just stuck in cache-land, but now I'm free. Thanks for your consideration.
I am trying to create a chatbot for a VoIP solution using NodeJS, I recently refactored all conversation handlers in their separate scripts for ease of reading on the entry point.
Those conversation handlers are structured as follows:
// foobar.js
const Help = require('.../utils/Help.js');
const Utils = require('.../utils/Utils.js');
const UserList = require('.../database/Users.json');
module.exports = {
conversation: (message) => {
// Code here
}
// other cool methods
}
This is what my folder architecture looks like: (important files are *marked*)
/chatbot
/src
/bin
/conversation
*foobar.js*
foobarbar.js
etc.js
/database
*Users.json*
/utils
*Help.js*
*Utils.js*
/node_modules
To me, it seems like I target the files I require correctly, however, on runtime, I am greeted with a splendid error
internal/modules/cjs/loader.js:605
throw err;
^
Error: Cannot find module '.../utils/Help.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
at Function.Module._load (internal/modules/cjs/loader.js:529:25)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (D:\Library\Documents\AIScroll\src\bin\conversation\foobar.js:1:76)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
No matter how many dots I put in .../utils/Help.js, I always have the same error. Whether there is only one or there are fifteen.
I bet it's a really silly mistake, too.
Cheers ahead of time ♪
./ = Current folder
../ = One folder up
../../ = Two folders up and so on...
So your code needs to be as follows:
const Help = require('../../utils/Help.js');
const Utils = require('../../utils/Utils.js');
const UserList = require('../../database/Users.json');
Multiple dot's wont work. It's always either ./ or ../.
You can however write ../ multiple times.
It should be ../../utils/Help.js etc.
The utils folder is 2 directories up
I suppose you have to get up to 2 levels:
const Help = require('../../utils/Help.js');
const Utils = require('../../utils/Utils.js');
const UserList = require('../../database/Users.json');
I have been given an automation framework in CucumberJS and node with selenium. But it has an older version of cucumber which relies on promises. In an attempt to avail latest synchronous step feature, I decided to upgrade the cucumberJS version (1.3.3 to 4.2.1)
Now the problem is the code that was used to invoke cucumber cli programmatically in index.js isnt working anymore. I made all the other changes in step definitions and world.js, but I am not able to figure out how do I run this thing via node, something like
node index.js --tags #SampleFeature
This used to work before with the older version but not anymore.
Code that was working before -
// execute cucumber
let cucumberCli = Cucumber.Cli(process.argv);
cucumberCli.run(succeeded => {
var code = succeeded ? 0 : 1;
function exitNow() {
process.exit(code);
}
if (process.stdout.write('')) {
exitNow();
} else {
process.stdout.on('drain', exitNow);
}
});
Now it throws the error like this after version update
/Users/../node_modules/babel-runtime/helpers/classCallCheck.js:7
throw new TypeError("Cannot call a class as a function");
^
TypeError: Cannot call a class as a function
at exports.default (/Users/../node_modules/babel-runtime/helpers/classCallCheck.js:7:11)
at Object.Cli (/Users/../node_modules/cucumber/lib/cli/index.js:78:34)
at Object.<anonymous> (/Users/../index.js:90:10)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
at startup (internal/bootstrap/node.js:228:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:576:3)
I googled a lot but did not find an alternative. Tried multiple things as calling Cli as class with new keyword, didn't work. Tried removing it and running via plain cucumber cli runner, didn't work.
PS. I come from a Cucumber with Java background where things were simpler :)
You need to create a new CLI object, then use it's .run method:
let runArgs = ['The cucumber args array here'];
let cliArgs = {argv : runArgs, cwd: process.cwd(), stdout: process.stdout};
let cli = (new require('cucumber').Cli)(cliArgs);
cli.run(); //Returns a promise
For reference I've employed the same approach with Typescript and cucumber 7.3.2
import { Cli } from '#cucumber/cucumber';
const runArgs = ['-p', argv['profile'], '--tags', argv['tags'], '--fail-fast'];
const cliArgs = { argv: runArgs, cwd: process.cwd(), stdout: process.stdout };
const cli = new Cli(cliArgs);
await cli.run();
I'm currently very interested in the comprehensive opportunites granted by electron.js and its modules. Unfortunately, I keep getting the same error in my renderer process (named 'connector.js') when trying to start my application.
Here is the error:
App threw an error during load
TypeError: Cannot match against 'undefined' or 'null'.
at Object.<anonymous> (D:\Eigene Dateien\Desktop\Coding\DesktopApps\EVT\extFunctions\connector\connector.js:2:44)
at Object.<anonymous> (D:\Eigene Dateien\Desktop\Coding\DesktopApps\EVT\extFunctions\connector\connector.js:22:3)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (D:\Eigene Dateien\Desktop\Coding\DesktopApps\EVT\main.js:9:1)
And here is my connector.js:
const $ = require('jquery');
const {BrowserWindow} = require('electron').remote;
let Remotewin = remote.getFocusedWindow();
$("#minimize").click(function(){
Remotewin.minimize();
});
$("#maximize").click(function(){
if(!Remotewin.isMaximized()){
Remotewin.maximize();
}else{
Remotewin.unmaximize();
}
});
$("#close").click(function(){
Remotewin.close();
});
As you can see clearly, I wanted to create my own menubar at the top frame of the window, but the functionality is getting seemingly demolished by this error. I already searched half of the internet and stackoverflow, but the every answer I found refered to a webpack and/or electron bug they couldn't directly influence.
That's why I want to clearly point out, that I am NOT using webpack in this project. Only external module I added is jquery, as you can see in the code.
So my question; Have you experiended this error in this context and do you maybe even know a solution? Or can you refer to someone with similiar problems?
Thank you in advance, J0nny
Since getFocusedWindow() is a a static method of BrowserWindow,
let Remotewin = remote.getFocusedWindow();
should be:
let Remotewin = BrowserWindow.getFocusedWindow();