How to fix connection timeout problem with MongoDB

Some of us have encountered a problem problem right after installing MongoDB, turns out we can’t connect. I personally get this: root@ghost:~# mongo MongoDB shell version v4.2.8 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb 2020-10-30T12:10:51.955+0100 E QUERY [js] Error: couldn’t connect to server 127.0.0.1:27017, connection attempt fa iled: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection timed out : connect@src/mongo/shell/mongo.js:341:17 @(connect):2:6 2020-10-30T12:10:51.958+0100 …

How to list IP tables in Linux

This is helpful for when you can’t access your localhost (127.0.0.1). Specially if you are having trouble accessing MongoDB after installation. Here is the command: iptables -L –line-numbers Sources: https://dba.stackexchange.com/questions/181693/mongodb-exception-connect-failed

How to locally configure a replica set in MongoDB

This post will guide you through the steps to set up a local replica set with two members and one arbiter. In a production environment the steps must be almost the same except that instead of starting three local MongoDB instances in different ports you would start an instance of MongoDB on each server with its own configuration file. This …

Permission Table for Linux (quick reference)

I am sure you have wondered what is the right permission for your file and tried to understand how it works, why there are numbers and letter and what all that mess means. Well here is a table that puts it in a very simple way, I am assuming you already know binary system, Linux and have a mind sharp …

How to parse JSON files in Node.JS ?

Quick tip using fs: let data = fs.readFileSync(“myFile.json”, ‘utf8’); console.log(typeof JSON.parse(data)); There is another way to do this that requires less effort. Using require directly, like so: const data = require(“myFile.json”); console.log(typeof data); Hope it helps.

How to pack NodeJS project into a tarball?

Today I needed to install my brand new NodeJS-developed CLI application in my computer. After a quick search on the Internet I became aware that NPM allows me to do that very easily. The command is: npm pack Run it inside the project that you want to pack (at the same level of the package.json file). Here is an example …

How to hash files in Node.JS

The process is quite simple actually. Unfortunately ,as much things in Node.js, it works asynchronously, for some applications this will be perfect, but for some others it will be a mess to wait for the freaking hash to do something else, anyway I am not going to discuss that here I actually like Node.js. Please note that in the following …

How to generate RSA key pair in Node.JS?

Very straight forward process. Not complicated at all, I would say that the most difficult part would be to actually tweak the options, however the code below actually works and provides you the time it took to generate the key pair as well, just for informational purposes. Run the following code in Node.js. const crypto = require(‘crypto’); const RSA = …