NodeJs

Uninstall and remove a package from project

If a package in your project is superfluous, it can be removed as follows: npm uninstall jade --save // or --save-dev If it is done as above, the package will be removed from the package.json file.

Organizing my Node.js imports

For structuring, all my imports have the following order: // core imports const http = require("http"); ... // third party imports const express = require('express'); ... // self made imports ... This is just my personal preference

Installing NodeJs form tar.gz

An explicit NodeJs version can be installed from teh tar.gz file. Below are the steps to install the prefered version. sij@sijmi:~/Downloads$ node -v bash: node: command not found sij@sijmi:~/Downloads$wget https://nodejs.org/dist/v14.9.0/node-v14.9.0-linux-x64.tar.gz sij@sijmi:~/Downloads$ sudo t...

Install and add a npm module to the project

In your Node.js project, there is a package.json file, which includes all the npm modules, your project depends on. To automatically add a npm module on install to this file, you have to enter the following command. npm i bcrypt --save The key is “–save”. Through that parameter, bcrypt will auto...

Hashing passwords with bcrypt

const bcrypt = require("bcrypt"); const myFunction = async () => { const password = "Res123456!"; const hashedPassword = await bcrypt.hash(password, 12); console.log(password); console.log(hashedPassword); const isMatch = await bcrypt.compare("Res123456", hashedPassword);...

Create a production server for a NodeJs wep app

I have created a NodeJs wep app, which I wanted to host on a unmanaged server. This guide shows how I have done it on an ubuntu 18.10 lts server. Environment variables for NodeJs If the web app is on a production server, it should know that. Otherwise some installed npm packeges log extensively....