I have a redis server which is working fine in my local but in ubuntu server is not working can someone gives the comment for installing redis in server
it is not working even with docker it is working only while i am running in local
const redis=require('redis');
var redisClient:any;
(async () => {
try {
redisClient = redis.createClient({ socket: { port: 6379 } });
await redisClient.connect();
// const redisClient = redis.createClient({
// port:"6379",
// host:'redis-service'
// });
redisClient.on('connect',()=>{
console.log('server connected to redis')
})
redisClient.on('ready',()=>{
console.log('Client Connect to redis and ready to use')
})
redisClient.on('error',(err:any)=>{
console.log(err)
})
redisClient.on('end',()=>{
console.log('Server disconnected from redis')
})
process.on('SIGINT',()=>{
redisClient.quit()
})
console.log('connected');
} catch (err) {
console.error(err)
}
})()
export{
redisClient
};
Make sure that Redis is not already running on the server. You can check this by running the command ps aux | grep redis. If Redis is running, you should see a line with the redis-server process.
Confirm that Redis is properly installed on your server by running redis-cli ping. If Redis is installed and running, it should return "PONG"
Check the Redis configuration file (redis.conf) and ensure that the IP and port settings match the settings on your local machine.
Make sure that the Redis server has the necessary permissions to access its data directory and that the correct ownership and permissions are set on its files.
Verify that the firewall rules on the server allow incoming connections on the Redis port (usually 6379)
Check for any compatibility issues between the version of Redis that you're running on your local machine and the version of Redis that's running on the Ubuntu server. If there's a version mismatch, it may be necessary to upgrade or downgrade one of the installations.
Try to run the Redis server with verbose output by running the command redis-server -v, this can give you some more information about the errors that are causing the server to fail.
Look at Redis log files, usually located in /var/log/redis for further clues about the cause of the problem.
Related
const redis = require('redis');
require('dotenv').config();
console.log(process.env.redisHost, ':', process.env.redisPort);
const redisClient = redis.createClient({
host: process.env.redisHost,
port: process.env.redisPort,
password: process.env.redisKey
});
redisClient.connect();
redisClient.on('error', err => console.log('Redis error: ', err.message));
redisClient.on('connect', () => console.log('Connected to redis server'));
module.exports = redisClient;
I tried this sample from redis docs but still I'm getting an error stating:
Redis error: connect ECONNREFUSED 127.0.0.1:6379
I logged the environment host and port variables to the console and I got the remote host ipv4 address, but still the client is trying to connect to localhost instead of remote host (I purposely uninstalled redis from my local device to check if the client is working as it is supposed to). I also confirmed that the remote redis host is working perfectly.
I also tried different methods like :
https://cloud.google.com/community/tutorials/nodejs-redis-on-appengine
redis.createClient(port, host, {auth_pass: password});
But still, I got the same error.
I am able to connect to the redis host via commandline:
redis-cli.exe -h XX.XX.XX.XXX -a Password
XX.XX.XX.XXX:6379> set name dhruv
OK
XX.XX.XX.XXX:6379> get name
"dhruv"
XX.XX.XX.XXX:6379> exit
I'm trying to use redis on nodejs for the first time, so don't have a proper idea but I think I am doing everything right.
Any solution/workaround will be helpful :D
It worked with this code:
const url = `redis://${process.env.redisHost}:${process.env.redisPort}`;
const redisClient = redis.createClient({
url,
password: process.env.redisKey
});
redisClient.connect();
can you check if in the destination the port is reachable. it maybe the firewall block your access
I am trying to run an Express server that would communicate with a local MongoDB instance. Everything runs on Ubuntu 18.04.5 on DigitalOcean.
I managed to set up the database, the authentication is made, but then after a few seconds the connection closes due to some mongodb dependencies (I think).
This is how I make the connection:
const httpsServer = https.createServer(credentials, app);
const mongooseConnection = mongoose
.createConnection(
`mongodb://user:pass#127.0.0.1:27017/Database?retryWrites=true&w=majority`,
{ useNewUrlParser: true, useUnifiedTopology: true }
);
mongooseConnection.on('error', console.error.bind(console, 'Connection error: '));
mongooseConnection.once('open', () => {
console.log("Connected to the DB");
httpsServer.listen(securePort, () => {
console.log(`Secure Express server listening on port ${securePort}`);
});
});
Node console:
Mongod:
Couldn't find much about this error. Most of what I've found is related to the MongoDB Atlas cloud service, but this is a local MongoDB instance. The common solution for when the connection closes like this seems to be whitelisting the IP. I think this is not the case as everything is local and I have nothing to do with the Atlas/Cluster.
I tried removing the node modules and updating them. I tried disabling cors and helmet. I'm stuck
I have deployed node API on Ubuntu server (AWS) but when I run my app it throw below error given in screen shot. due to I am not able to make API requst.
I have trid to kill port and execute it again but it gives e same error
my node app is running on 8081 on local machine
var connection = mongoose
.connect(url, option)
.then(result => {
app.listen(PORT);
console.log("Running RestHub on port " + PORT)
})
.catch(err => {
console.log(err);
});
after uploading code in Ubuntu sever it does not work
I am struggling to fix this issue since yesterday but could not fix yet.
Please your help would be highly appreciated
Thanks you
In my node web server, I am using a the npm module redis.
when I run my code...
const client = redis.createClient();
client.on("error", function (err) {
console.log("Error " + err);
});
client.hmset(["key", "test keys 1", "test val 1", "test keys 2", "test val 2"], function (err, res) {});
I get an error:
Error Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
I don't have a redis database installed. Do I need that?
If not, anything I have missed in my code?
Yes, you need to install Redis and ensure the server is running. This is a link to the official page for downloading the redis.
In your application code, you need to ensure you are connecting to Redis server with the right port and host address. By default, Redis server should be running on 127.0.0.1:6379 and that is where redis.createClient would try to connect to by default. If your Redis server is running on another port or host, then you need to specify those details when connecting e.g:
redis.createClient({
host: '<the host where redis is running>',
port: '<the port where redis is running>'
});
You can check here for more info on the options you can provide when connecting to Redis server with redis.createClient.
I created a very simple Node.JS script which is suppose to connect to a server on port 3200. The code works great on Windows 8.1 x64, but when I moved it to a Ubuntu Server machine I am getting a ECONNREFUSED.
I tried to connect via IP Address and the Domain Name, but neither work. It always gives me ECONNREFUSED.
When I SSH into the Ubuntu Server I can do a telnet to the server/port and it works fine. Also pinging the server works. Just Node.JS doesnt connect.
Server:
Ubuntu Server 12.04.3 LTS (precise)
Here is the code:
var net = require('net');
var socket = net.connect({port: 3200, host: '172.19.16.203'}, function() {
// Connection Successful
console.log('Socket connected...');
// Data Received from Server
socket.on('data', function(d) {
console.log('data');
});
socket.on('end', function() {
});
socket.on('error', function(e) {
});
});
I found the solution. I was running my script by the following command:
node test.js
I guess the node is an old version. I upgraded the OS to the latest version and then did:
apt-get install nodejs
I run the script like following:
nodejs test.js
And it works!