Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the difference between node:crypto and crypto?

I want to use the randomUUID function from node:crypto module but I can import it in two ways, either:

import { randomUUID } from 'crypto'

or:

import { randomUUID } from 'node:crypto'

What is the difference between the two imports? I know that Node.js can be built without including support for the node:crypto module but it does not help me much in understanding the difference.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Per the documentation:

node: URLs are supported as an alternative means to load Node.js
builtin modules. This URL scheme allows for builtin modules to be
referenced by valid absolute URL strings.

import fs from 'node:fs/promises';

They’ve been supported by import since v12.20.0/v14.13.1, and by require since v14.18.0/v16.0.0.

Note that while most builtin modules are available either with or without the prefix, some newer modules (like node:test) are accessible only via the prefixed name. I try to consistently use the prefixes whenever using Node.js modules so it’s clear that they’re builtin rather than third party.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading