How to Encrypt / Decrypt strings with RSA in Node.JS

Interesting things that go through my mind during lock-down haha! const crypto = require(‘crypto’); const PASSPHRASE = ‘I had learned that some things are best kept secret.’; const KEY_PAIR_OPTIONS = { modulusLength: 2048, publicKeyEncoding: { type: ‘spki’, format: ‘pem’ }, privateKeyEncoding: { type: ‘pkcs8’, format: ‘pem’, cipher: ‘aes-256-cbc’, passphrase: PASSPHRASE } }; const KEY_PAIR = crypto.generateKeyPairSync(‘rsa’, KEY_PAIR_OPTIONS); const RSA_PRK = …

Random Password Generator in Node.JS

The other day I thought about how to generate passwords from random arrays. Here is what I came up with: /* * RaNdom Password Generator */ const crypto = require(‘crypto’); const PASSWORD_LENGTH = 18; const LOWERCASE_ALPHABET = ‘abcdefghijklmnopqrstuvwxyz’; // 26 chars const UPPERCASE_ALPHABET = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’; // 26 chars const NUMBERS = ‘0123456789’; // 10 chars const SYMBOLS = ‘,./<>?;\'”:[]\\|}{=-_+`~!@#$%^&*()’; // …

How to deploy Express.JS web application on HawkHost with cPanel?

Here is a step by step guide based on my experience on how to deploy your Express.JS web application with cPanel on HawkHost servers. First, the versions I am using are: cPanel v90.0.16 Express.JS v4.16.0 Node.JS v12.16.1 NPM v6.14.4 Now it’s time to login to your cPanel, and do the following Upload your application folder to the server: You can …

How to generate X.509v3 self-signed certificate in PEM format with Node.JS

I thought this would be way harder, but thanks to the node-forge library and their perfect documentation, this was a breeze! After some experimentation I have modified their example code to have the very basic way to generate a X.509v3 self-signed certificate in PEM format. // import libraries const forge = require(‘node-forge’); const crypto = require(‘crypto’); const fs = require(‘fs’); …

Markdown cheat sheet for Visual Studio Code

Here is a cheat sheet that I found somewhere that will work with Visual Studio Code MD files: “# README” <!– M A R K D O W N   C H E A T  S H E E T –><!– Headings –># Heading 1## Heading 2### Heading 3#### Heading 4##### Heading 5###### Heading 6<!– Italics –>*This text* is italic\*This text\* is not italic_This text_ is italic<!– Strong …

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