Depends on the version of Node Redis that you are using. Since it looks like you are using Node Redis 3.x it would look like this:
const client = redis.createClient({
host: "localhost",
port: 6379,
password: "1234",
user: "username"
});
You could also connect using a connection string:
const client = redis.createClient("redis://username:1234@localhost:6379");
Full documentation for 3.x is available on the tagged branch in the GitHub repo for Node Redis.
That said, I would recommend using Node Redis 4.x as it supports Promises, newer Redis commands, and many common Redis modules like RedisJSON and RediSearch.
To connect using 4.x:
const client = redis.createClient({
socket: {
host: "localhost",
port: 6379
}
password: "1234",
username: "username"
});
or:
const client = redis.createClient({ url: "redis://username:1234@localhost:6379" });
Details on connecting using Node Redis 4.x can be found in the README on the main branch of Node Redis and in the Client Configuration Guide.