Nohm can't find Redis client - node.js

I'm trying to follow Tomas Davis's tutorial on Backbone.js but I can't make the server run.
He gives a standard node.js server with CORS enabled and a Redis database. Here's the link to his GitHub :
--> https://github.com/thomasdavis/video-backbone-beginner-server
There was one further problem that I solved, so you'll have to replace :
nohm.setClient(redis);
by :
redis.on("connect", function() {
nohm.setClient(redis);
console.log("Nohm Connected to Redis Client");
})
After that fix, Nohm seems to connect to Redis but still doesn't work. Here's the stack-trace :
{ name: 'Nohm Error',
message: 'Did not find a viable redis client in Nohm or the model: User' }
/node-projects/backbone/node_modules/nohm/lib/properties.js:27
if (!this.properties[key]) {
^
TypeError: Cannot read property 'firstname' of undefined
at Nohm.property (/node-projects/backbone/node_modules/nohm/lib/properties.js:27:23)
at Nohm.property (/node-projects/backbone/node_modules/nohm/lib/properties.js:22:23)
at Object.<anonymous> (/node-projects/backbone/example_server.js:110:6)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
The Redis server process is up though.
Does anyone know how to make the server work ?
Thank you in advance !

Sorry for the late reply, hope it'll still be of some help.
I cannot be 100% sure what the problem here is without knowing what /node-projects/backbone/example_server.js:110 is.
But my best guess is that while you wait for the connection you are trying to do other actions with nohm. Nohm then tries to access the client before the client is set.
This causes the init function of a model to fail, thus not properly initializing the internal variables (amongst others properties).
You need to wait with all model interaction until the redis connection is established. Or you revert to the old method of:
nohm.setClient(redis);
This should then queue up the redis commands until the connection is established, if I'm not mistaken.

Related

ReferenceError: window is not defined in godash

I am trying to build a board game and want to use godash to create a board state and update it. I have successfully installed godash into my package.json, but when I require it in the back-end, in my server.js (the file in which I run my server),
var godash = require ('godash');
and I run node server.js, the CLI responds with this error:
ReferenceError: window is not defined
at Object.<anonymous> (C:\Users\Chidi\gt\projects\Chess-vs-Go\node_modules\godash\dist\godash.js:1:194)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\Users\Chidi\gt\projects\Chess-vs-Go\game_state\go_state.js:2:14)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
I've seen various "window is not defined" questions on this site in my effort to solve this problem, and the general solution seems to be that the code should be used in a browser environment. However, this is godash, an npm package that is to be used in the back-end. I have tried updating node.js and npm to their latest versions, but the problem still persists. I feel like I am making an obvious error that I can't see, because I went to the github page for godash and did not find any closed or open issues similar to this one. Does anyone know what the issue is, and how I can resolve it?
So, upon further research, I found that there are ways to use npm packages in the browser (e.g via browserify) This allowed me to use godash in the browser, where it was looking for a window object.

Error showing at npm start but then runs smoothly... [MongoError: Topology closed]

So I have this website in Express-Node/MongoDb, managed to install it and have it run smoothly with no errors whatsoever. Then, as you do, I updated 3 miserable files, added a couple of lines of code, nothing fancy (worked locally as well), updated everything on the live server and after the npm start got the error message below (multiple times, everytime I make a call to the db I guess).
MongoDB connection error: MongoError: Topology closed
at NativeTopology.close (/home/jelastic/ROOT/node_modules/mongodb/lib/core/sdam/topology.js:325:38)
at /home/jelastic/ROOT/node_modules/mongodb/lib/mongo_client.js:267:21
at maybePromise (/home/jelastic/ROOT/node_modules/mongodb/lib/utils.js:719:3)
at MongoClient.close (/home/jelastic/ROOT/node_modules/mongodb/lib/mongo_client.js:248:10)
at /home/jelastic/ROOT/node_modules/mongoose/lib/connection.js:711:20
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (/home/jelastic/ROOT/node_modules/mongoose/lib/connection.js:709:19)
at Mongoose.connect (/home/jelastic/ROOT/node_modules/mongoose/lib/index.js:335:15)
at Object.<anonymous> (/home/jelastic/ROOT/controllers/visitController.js:7:10)
at Module._compile (internal/modules/cjs/loader.js:1200:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
at Module.load (internal/modules/cjs/loader.js:1049:32)
at Function.Module._load (internal/modules/cjs/loader.js:937:14)
at Module.require (internal/modules/cjs/loader.js:1089:19)
at require (internal/modules/cjs/helpers.js:73:18)
at Object.<anonymous> (/home/jelastic/ROOT/routes/activity.js:4:24)
I check my connection credentials to the db, everything seems ok... but hey, sometimes you forget a period, a parenthesis, whatever... so I rollback to a previous working version and... got the same error. What's weird too is that the site works just fine as far as I can see. Everything loads fine, I was able to insert new documents to collections, delete some... No error shows up in the console after the the initial display.
I don't get it. What could possibly trigger this error if I ruled out my code?? I don't like it when I get an error that seems blocking yet everything seems to work fine...
Any insight would be much appreciated!!

Issues in the 'Fabcar' tutorial when bringing up a Kafka-based ordering service

I've brought up a Kafka-based ordering service in the Fabcar network by modifying some docker composition/configuration files, which is one of the tutorials on Hyperledger Fabric readthedocs.
These are the issues I've suffered from. Could you please tell me how to resolve them or even one of them?
I'd like to have containers start up in a specific order with 'wait-for-it.sh' script so that the orderer starts trying to connect to the Kafka cluster right after it is ready to perform commands. Do you happen to know how I should apply the script to my docker composition file?
When I executed "enrollAdmin.js" file in order to register an admin account with node enrollAdmin.js on the network in the same way as I did on the unmodified network,
This error message is shown and it doesn't work:
~/fabric-samples/fabcar/node_nodules/fabric-
client/lib/Client.js:746
async _createOrUpdateChannel(request, have_envelop) {
^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected Identifier
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/~/fabric-samples/fabcar/node_modules/fabric-client/index.js:25:18)
at Module._compile (module.js:570:32)
I took a look at Client.js file and was trying to understand how it works, but I have no idea what it is for and why it causes the issue.
Please help me resolve this issue if you know how.
Update Your nodejs .
check node version
node -v
It shoulb be greater than 8.0.0.

Node JS app on OpenShift gives error 503

So I created a NodeJS app for a college project which monitors page loading speed. In order to record said speed I need people to go to the web application, go to a certain page and hit a button a couple of times.
So I looked up a way to host this app, free of charge, and came up with OpenShift.
After figuring out how it all worked I managed to setup an OpenShift git-repository and I am able to push my changes to the server.
However upon visiting my page I kept getting error 503. Initially I thought it was a node modules error so I found npm shrinkwrap which solved npm version issues. The error, is still around.
When I run the app locally, I get no errors whatsoever and all modules are installed correctly. They are also in a package.json file (I used npm install --save for all my modules, so no manual editing was performed).
These are the first couple of lines from using the tail-command and whopping the result into a text file.
==> app-root/logs/nodejs.log <==
at Connection.connect (/var/lib/openshift/550db5624382ecf8f400000f/app>root/runtime/repo/node_modules/mysql/lib/Connection.js:109:18)
at Object.<anonymous> (/var/lib/openshift/550db5624382ecf8f400000f/approot/runtime/repo/server.js:28:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
DEBUG: Program node server.js exited with code 8
DEBUG: Starting child process with 'node server.js'
I also found this:
==> app-root/logs/nodejs.log <==
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)
--------------------
at Protocol._enqueue (/var/lib/openshift/550db5624382ecf8f400000f/app-root/runtime/repo/node_modules/mysql/lib/protocol/Protocol.js:135:48)
at Protocol.handshake (/var/lib/openshift/550db5624382ecf8f400000f/app-root/runtime/repo/node_modules/mysql/lib/protocol/Protocol.js:52:41)
at Connection.connect (/var/lib/openshift/550db5624382ecf8f400000f/app-root/runtime/repo/node_modules/mysql/lib/Connection.js:109:18)
at Object.<anonymous> (/var/lib/openshift/550db5624382ecf8f400000f/app-root/runtime/repo/server.js:28:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
DEBUG: Program node server.js exited with code 8
Any idea's?
Mine did the same when I first pushed to OpenShift. I think I had to review some references and make some slight changes. My log on OpenShift indicated that such-and-such file couldn't be found. Yours might, too, if you review the entire thing.
For example, this is the "after" version of something I edited:
self.app.set('views', path.join(__dirname, 'views'));
I might have had just this before:
self.app.set('views', '/views');
Hope that helps.
Well... you've got...
Error: connect ECONNREFUSED
...which suggests that Express couldn't connect to the database. Maybe you've got dev versus prod credentials going on and the code's trying to use the local credentials, the local database name, the local username, the local server, etc.
I'm using MongoDB (no credentials locally) and have created a /db.js file to store all that. And then my /server.js selects which variable:
if (typeof process.env.OPENSHIFT_NODEJS_IP === "undefined") { mongoose.connect(dbConfig.devurl); } else { mongoose.connect(dbConfig.produrl); }
Note the two different variables after dbConfig.varname.

Use edge js on openshift

I'm trying to run C# on my OpenShift cartridge with Edge.js. It runs really good on my Windows PC and I would like to have it running on the cloud.
I'm guessing it runs on a Linux environment but I'm not shure.
At first I tried to make it work with my MSSQL DB and than move on to the C# assembly.
Nevertheless I'm doing the same steps as how I've got it to work on my Windows machine but I'm getting thesame errors over and over again.
I've added edge and edge-sql to my npm and my package.json.
Then I've make a simple count to my MSSQL DB.
When I'm running it locally it works great. Than I push it to OpenShift and I tail the application, because the front-end gives me an Error 503, and the next thing I know the following error makes me keepings my hands in my hair.
Error: The edge native module is not available at /var/lib/openshift/54d26260fcf
933d05e00021a/app-root/runtime/repo/node_modules/edge/build/Release/edge.node. Y
ou can use EDGE_NATIVE environment variable to provide alternate location of edg
e.node. If you need to build edge.node, follow build instructions for your platf
orm at https://github.com/tjanczuk/edge
at Object.<anonymous> (/var/lib/openshift/54d26260fcf933d05e00021a/app-root/
runtime/repo/node_modules/edge/lib/edge.js:33:11)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/lib/openshift/54d26260fcf933d05e00021a/app-root/
runtime/repo/server.js:5:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
DEBUG: Program node server.js exited with code 8
DEBUG: Starting child process with 'node server.js'
/var/lib/openshift/54d26260fcf933d05e00021a/app-root/runtime/repo/node_modules/e
dge/lib/edge.js:33
throw new Error('The edge native module is not available at ' + builtEdge
Could somebody help me to fix this error or maybe explain to me why it could / wont work?
If edge requires a native windows environment to run C#, then it will not work on OpenShift, which runs on Red Hat Linux.

Resources