Unable to get strong-remote example to work - node.js

I'm trying the example: https://github.com/strongloop/strong-remoting/blob/master/example/simple.js
When I invoke the curl, I get: curl: (52) Empty reply from server
and the node program exits with:
sm#valley:~/Documents/Projects/test/loopback.io/remoting$ node simple.js
/home/sm/Documents/Projects/test/loopback.io/node_modules/strong-remoting/node_modules/express/lib/router/index.js:603
return fn.apply(this, arguments);
^
TypeError: Cannot call method 'apply' of undefined
at Object. (/home/sm/Documents/Projects/test/loopback.io/node_modules/strong-remoting/node_modules/express/lib/router/index.js:603:15)
at Object.immediate._onImmediate (timers.js:348:16)
at processImmediate [as _immediateCallback] (timers.js:330:15)
Any idea what I'm missing ?

You may want to also look at https://github.com/strongloop/loopback-example-remote. It's an example of the LB remote connector, which uses strong-remoting. Not sure if it fits your use case, but AFAIK it works.

Related

transaction code "require('#arangodb').db;" can't be packaged

zeit-pkg is a tool for package nodejs code. zeit-pkg also support require('arangojs'). But zeit-pkg returned error for meet const db = require('#arangodb').db; zeit-pkg returns error.
> Error! TypeError: Cannot read property '0' of null
at shortFromAlias (/usr/local/lib/node_modules/pkg/lib-es5/walker.js:69:49)
at Walker._callee5$ (/usr/local/lib/node_modules/pkg/lib-es5/walker.js:894:25)
at tryCatch (/usr/local/lib/node_modules/pkg/node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (/usr/local/lib/node_modules/pkg/node_modules/regenerator-runtime/runtime.js:296:22)
at Generator.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/pkg/node_modules/regenerator-runtime/runtime.js:114:21)
at step (/usr/local/lib/node_modules/pkg/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at /usr/local/lib/node_modules/pkg/node_modules/babel-runtime/helpers/asyncToGenerator.js:30:13
at <anonymous>
I want to know what's particular in require('#arangodb').db. It's whether any replacement method exists for writing transaction. Or any other package tools can support require('#arangodb').db;
zeit-pkg is compiles JavaScript code into an executable, this is not compatible with Foxx, as Foxx is the executable that runs your JavaScript code.
If you want to minimize/uglify/mangle your code take a look at WebPack, this document from ArangoDB shows you how to get WebPack working with Foxx, as it marks those libraries as 'external' libraries that get skipped for processing.

error: uncaughtException: require(...).invokeRolesPolicies is not a function

I am using MEAN.JS for developing a web app, but for some reason after I made few changes, well mostly copied and paste new modules into the app I see the error as below:
error: uncaughtException: require(...).invokeRolesPolicies is not a function
I dont know why is this happening, anyone has any clue how to fix this?
This is the whole error message:
TypeError: require(...).invokeRolesPolicies is not a function
at C:\oferdo\oferdo\config\lib\express.js:180:39
at Array.forEach (native)
at Object.module.exports.initModulesServerPolicies (C:\oferdo\oferdo\config\lib\express.js:179:32)
at Object.module.exports.init (C:\oferdo\oferdo\config\lib\express.js:252:8)
at C:\oferdo\oferdo\config\lib\app.js:29:23
at C:\oferdo\oferdo\config\lib\mongoose.js:36:15
at C:\oferdo\oferdo\node_modules\mongoose\lib\connection.js:284:19
at open (C:\oferdo\oferdo\node_modules\mongoose\lib\connection.js:511:17)
at C:\oferdo\oferdo\node_modules\mongoose\lib\connection.js:518:7
at C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\lib\db.js:1504:5
at handleCallback (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\lib\utils.js:96:12)
at _callback (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\lib\db.js:1420:5)
at C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\lib\db.js:1463:7
at C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:1416:5
at finish (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\auth\scram.js:157:16)
at handleEnd (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\auth\scram.js:170:7)
at C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\auth\scram.js:264:17
at commandCallback (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:1194:9)
at Callbacks.emit (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:119:3)
at null.messageHandler (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:358:23)
at Socket. (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\connection\connection.js:292:22)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:153:18)
at Socket.Readable.push (_stream_readable.js:111:10)
at TCP.onread (net.js:531:20)
Actually, this is nothing to do with incorrectly named files.
You need to make sure that you have the invokeRolesPolicies function defined within your policies file. The minimum required is:
'use strict';
var acl = require('acl');
acl = new acl(new acl.memoryBackend());
exports.invokeRolesPolicies = function () {};
The reason why is that the express.js lib defined in mean.js assumes this is set, and tries to call it, hence the error.
You'll get this error if you have an incorrectly named file under your module's server > policies directory, so check there for any inconsistently named files.
EDIT
I see now that it's not the naming of the file but if you have a file in the policies directory that doesn't contain this method, it will produce this error. In my case I had temporarily commented out the code in a file in this directory in preparation for removal.

Selenium mocha Tests

I was trying to put an implicit wait in selenium java script with mocha but i see the following error:
ReferenceError: timeUnit is not defined
Below is the code snippet i used:
driver.manage().timeouts().implicitlyWait(20, timeUnit.SECONDS);
and the stack trace I see is:
at Context.<anonymous> (C:\node_modules\Script\login_scenario.js:32:50)
at C:\node_modules\Script\node_modules\selenium-webdriver\testing\index.js:142:19
at new promise.Promise (C:\node_modules\Script\node_modules\selenium-webdriver\lib\webdriver\promise.js:355:5)
at controlFlowExecute (C:\node_modules\Script\node_modules\selenium-webdriver\testing\index.js:127:14)
at promise.ControlFlow.runInFrame_ (C:\node_modules\Script\node_modules\selenium-webdriver\lib\webdriver\promise.js:1877:20)
at promise.ControlFlow.runEventLoop_ (C:\node_modules\Script\node_modules\selenium-webdriver\lib\webdriver\promise.js:1755:8
at null.<anonymous> (C:\node_modules\Script\node_modules\selenium-webdriver\lib\webdriver\promise.js:2056:12)
at goog.async.run.processWorkQueue (C:\node_modules\Script\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21)
: Task: Automation of Shop Management Login scenario
at Context.ret (C:\node_modules\Script\node_modules\selenium-webdriver\testing\index.js:126:10)
at Test.Runnable.run (C:\Users\kashyap\AppData\Roaming\npm\node_modules\mocha\lib\runnable.js:233:15)
at Runner.runTest (C:\Users\kashyap\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:387:10)
at C:\Users\kashyap\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:470:12
at next (C:\Users\kashyap\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:312:14)
at C:\Users\kashyap\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:322:7
at next (C:\Users\kashyap\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:257:23)
at Immediate._onImmediate (C:\Users\kashyap\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:289:5)
at processImmediate [as _immediateCallback] (timers.js:358:17)
implicitlyWait() in javascript selenium bindings accepts a single argument - a timeout in milliseconds:
driver.manage().timeouts().implicitlyWait(20000);
You are probably mixing it up with implicitlyWait() method from java selenium bindings, which allows you to specify the timeout unit alongside with the timeout itself.

SailsJs Invalid module error

After I installed lodash or async plug-ins,
Console shows those error messages when I launch sails.js.
but I don't know what cause those error messages.
I need to solve this problem. please anyone help me.
error: A hook (`userconfig`) failed to load!
error: Error: Invalid module:[object Object]
at /Users/johndo/github/sails/testProject/node_modules/sails/node_modules/sails-build-dictionary/index.js:83:15
at forOwn (/Users/johndo/github/sails/testProject/node_modules/lodash/dist/lodash.js:2105:15)
at Function.forEach (/Users/johndo/github/sails/testProject/node_modules/lodash/dist/lodash.js:3302:9)
at buildDictionary (/Users/johndo/github/sails/testProject/node_modules/sails/node_modules/sails-build-dictionary/index.js:74:4)
at Function.module.exports.aggregate (/Users/johndo/github/sails/testProject/node_modules/sails/node_modules/sails-build-dictionary/index.js:190:9)
at Array.loadOtherConfigFiles [as 0] (/Users/johndo/github/sails/testProject/node_modules/sails/lib/hooks/moduleloader/index.js:164:27)
at /Users/johndo/github/sails/testProject/node_modules/sails/node_modules/async/lib/async.js:459:38
at Array.forEach (native)
at _each (/Users/johndo/github/sails/testProject/node_modules/sails/node_modules/async/lib/async.js:32:24)
at Object.async.auto (/Users/johndo/github/sails/testProject/node_modules/sails/node_modules/async/lib/async.js:430:9) [Error: Invalid module:[object Object]]
error: Error: Invalid module:[object Object]
at /Users/johndo/github/sails/testProject/node_modules/sails/node_modules/sails-build-dictionary/index.js:83:15
at forOwn (/Users/johndo/github/sails/testProject/node_modules/lodash/dist/lodash.js:2105:15)
at Function.forEach (/Users/johndo/github/sails/testProject/node_modules/lodash/dist/lodash.js:3302:9)
at buildDictionary (/Users/johndo/github/sails/testProject/node_modules/sails/node_modules/sails-build-dictionary/index.js:74:4)
at Function.module.exports.aggregate (/Users/johndo/github/sails/testProject/node_modules/sails/node_modules/sails-build-dictionary/index.js:190:9)
at Array.loadOtherConfigFiles [as 0] (/Users/johndo/github/sails/testProject/node_modules/sails/lib/hooks/moduleloader/index.js:164:27)
at /Users/johndo/github/sails/testProject/node_modules/sails/node_modules/async/lib/async.js:459:38
at Array.forEach (native)
at _each (/Users/johndo/github/sails/testProject/node_modules/sails/node_modules/async/lib/async.js:32:24)
at Object.async.auto (/Users/johndo/github/sails/testProject/node_modules/sails/node_modules/async/lib/async.js:430:9) [Error: Invalid module:[object Object]]
It looks like it's experiencing an error while parsing your configuration files. Try rolling back your changes.
Also, lodash and async come as globals in sails, so you don't need to install them. Just go to config/globals and uncomment _(lodash). That might fix your problem, as maybe sails is having a conflict between its installed version and yours.

OpenID for Node.js cannot run the sample server

When I try to run the sample nodejs server using openid found at
http://ox.no/software/node-openid
I get the following trace:
/home/ubuntu/node_modules/openid/openid.js:868
return callback({ message: 'No providers found for the given identifier'
^
TypeError: undefined is not a function
at /home/ubuntu/node_modules/openid/openid.js:868:14
at /home/ubuntu/node_modules/openid/openid.js:656:13
at /home/ubuntu/node_modules/openid/openid.js:612:11
at /home/ubuntu/node_modules/openid/openid.js:254:9
at IncomingMessage.<anonymous> (/home/ubuntu/node_modules/openid/openid.js:258:32)
at IncomingMessage.emit (events.js:88:20)
at HTTPParser.onMessageComplete (http.js:137:23)
at CleartextStream.ondata (http.js:1150:24)
at CleartextStream._push (tls.js:375:27)
at SecurePair.cycle (tls.js:734:20)
Perhaps the problem is the openid_identifier I supply on the first page. I have tried
yahoo.com
www.google.com/accounts/o8/id
www.google.com/accounts/o9/ud
When I try www.google.com/accounts/o8/id I get a slightly different trace:
/home/ubuntu/node_modules/openid/openid.js:895
return callback(null, authUrl);
^
TypeError: undefined is not a function
at successOrNext (/home/ubuntu/node_modules/openid/openid.js:895:18)
at /home/ubuntu/node_modules/openid/openid.js:1008:3
at successOrNext (/home/ubuntu/node_modules/openid/openid.js:909:9)
at /home/ubuntu/node_modules/openid/openid.js:931:5
at /home/ubuntu/node_modules/openid/openid.js:678:7
at /home/ubuntu/node_modules/openid/openid.js:544:16
at /home/ubuntu/node_modules/openid/openid.js:254:9
at IncomingMessage.<anonymous> (/home/ubuntu/node_modules/openid/openid.js:258:32)
at IncomingMessage.emit (events.js:88:20)
at HTTPParser.onMessageComplete (http.js:137:23)
Anyone have any idea what I've done wrong, how I can fix it?
At least for me the following worked like a charm:
git clone git#github.com:havard/node-openid.git
cd node-openid/
sudo node sample.js
I then launched my browser to localhost and logged in with Google's address: https://www.google.com/accounts/o8/id
It worked fine. So it looks like the sample on their website is a bit out of date while the one in their git repo works.

Resources