You must start experimenting with these build in API to replace famous NPM packages

Adel Benyahia
3 min readDec 22, 2022
Photo by Gabriel Heinzer on Unsplash

You can start using these experimental build-in API to replace these well known NPM packages

  1. nodemon
  2. uuid
  3. bcrypt
  4. jsonwebtoken
  5. date-fns and moment

1. nodemon

Yes you can uninstall nodemon right now and use the build-in experimental “watch” in node v18

Running in ‘watch’ mode using node --watch restarts the process when an imported file is changed.

You can use watch mode by enabling --watch flag to watch the entry point and any imported module

Node v18 notable changes

node --watch server.js

Or a directory

node --watch-path=./source

You can these lines to your package.json

 "scripts": {
"start": "node server",
"dev": "node --watch server"
},

2. uuid

You can replace the uuid package with the new build in javascript API crypto to generate unique id for your web application

and guess what? its very easy and straightforward

let uuid = crypto.randomUUID();
console.log(uuid)

crypto API randomUUID

3. bcrypt

You can use crypto.scrypt() to generate haches for passwords

Provides an asynchronous scrypt implementation. Scrypt is a password-based key derivation function that is designed to be expensive computationally and memory-wise in order to make brute-force attacks unrewarding.

crypto.scrypt(password, salt, keylen[, options], callback)

Provides an asynchronous scrypt implementation. Scrypt is a password-based key derivation function that is designed to be expensive computationally and memory-wise in order to make brute-force attacks unrewarding.

The salt should be as unique as possible. It is recommended that a salt is random and at least 16 bytes long. See NIST SP 800–132 for details.

When passing strings for password or salt, please consider caveats when using strings as inputs to cryptographic APIs.

The callback function is called with two arguments: err and derivedKey. err is an exception object when key derivation fails, otherwise err is null. derivedKey is passed to the callback as a Buffer.

An exception is thrown when any of the input arguments specify invalid values or types.

Example

const {
scrypt,
} = require('node:crypto');

// Using the factory defaults.
scrypt('password', 'salt', 64, (err, derivedKey) => {
if (err) throw err;
console.log(derivedKey.toString('hex')); // '3745e48...08d59ae'
});
// Using a custom N parameter. Must be a power of two.
scrypt('password', 'salt', 64, { N: 1024 }, (err, derivedKey) => {
if (err) throw err;
console.log(derivedKey.toString('hex')); // '3745e48...aa39b34'
});

4. jsonwebtoken

jsonwebtoken package is used to sign and verify web tokens, we can know use the build in crypt API to replace this package.

crypto.sign(algorithm, data, key[, callback])

Calculates and returns the signature for data using the given private key and algorithm.

crypto.verify(algorithm, data, key, signature[, callback])

Verifies the given signature for data using the given key and algorithm.

For more information about the crypto API, visit this link

https://nodejs.org/api/crypto.html

5. date-fns and moment

You can use the new intl API, with is the new javascript API to manage Date and Time

The Intl object is the namespace for the ECMAScript Internationalization API, which provides language sensitive string comparison, number formatting, and date and time formatting. The Intl object provides access to several constructors as well as functionality common to the internationalization constructors and other language sensitive functions.

More information here

--

--

Adel Benyahia

Web application developer (HTML │ CSS │ JS | ReactJS | NextJS | NestJS | MERN)