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.
>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.