You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an application supposed to run in docker container (I am new to node apps) along with redis container and it uses the redis client. The code is
var express = require('express');
var app = express();
var redis = require('redis');
var client = redis.createClient(6379, 'redis');
client.on("error", function (err) {
console.error("Redis error", err);
});
app.get('/', function (req, res) {
res.redirect('/index.html');
});
app.get('/json', function (req, res) {
client.hlen('wallet', function (err, coins) {
client.get('hashes', function (err, hashes) {
var now = Date.now() / 1000;
res.json( {
coins: coins,
hashes: hashes,
now: now
});
});
});
});
app.use(express.static('files'));
var server = app.listen(80, function () {
console.log('WEBUI running on port 80');
but when I run both containers, redis is up and running but the one that has the node app exits with the error
TypeError: client.hlen is not a function
at C:\Projects\Docker\Kubernetes\Container.Training\orchestration-workshop\dockercoins\webui\webui.js:15:12
at Layer.handle [as handle_request] (C:\Projects\Docker\Kubernetes\Container.Training\orchestration-workshop\dockercoins\webui\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Projects\Docker\Kubernetes\Container.Training\orchestration-workshop\dockercoins\webui\node_modules\express\lib\router\route.js:144:13)
at Route.dispatch (C:\Projects\Docker\Kubernetes\Container.Training\orchestration-workshop\dockercoins\webui\node_modules\express\lib\router\route.js:114:3)
at Layer.handle [as handle_request] (C:\Projects\Docker\Kubernetes\Container.Training\orchestration-workshop\dockercoins\webui\node_modules\express\lib\router\layer.js:95:5)
at C:\Projects\Docker\Kubernetes\Container.Training\orchestration-workshop\dockercoins\webui\node_modules\express\lib\router\index.js:284:15
at Function.process_params (C:\Projects\Docker\Kubernetes\Container.Training\orchestration-workshop\dockercoins\webui\node_modules\express\lib\router\index.js:346:12)
at next (C:\Projects\Docker\Kubernetes\Container.Training\orchestration-workshop\dockercoins\webui\node_modules\express\lib\router\index.js:280:10)
at expressInit (C:\Projects\Docker\Kubernetes\Container.Training\orchestration-workshop\dockercoins\webui\node_modules\express\lib\middleware\init.js:40:5)
at Layer.handle [as handle_request] (C:\Projects\Docker\Kubernetes\Container.Training\orchestration-workshop\dockercoins\webui\node_modules\express\lib\router\layer.js:95:5)
The text was updated successfully, but these errors were encountered:
var express = require('express');
var app = express();
var redis = require('redis');
var client =async ()=>{return await redis.createClient(6379, 'redis');}
client.on("error", function (err) {
console.error("Redis error", err);
});
client.connect();
app.get('/', function (req, res) {
res.redirect('/index.html');
});
app.get('/json', async function (req, res) {
await client.hlen('wallet', function (err, coins) {
client.get('hashes', function (err, hashes) {
var now = Date.now() / 1000;
res.json( {
coins: coins,
hashes: hashes,
now: now
});
});
});
});
You are accessing hlen before even initiating the client connection, need to use connect() to initate the connection.
You can refer #235 for accessing the result.
This should work
Description
I have an application supposed to run in docker container (I am new to node apps) along with redis container and it uses the redis client. The code is
app.use(express.static('files'));
var server = app.listen(80, function () {
console.log('WEBUI running on port 80');
but when I run both containers, redis is up and running but the one that has the node app exits with the error
The text was updated successfully, but these errors were encountered: