Home > OS >  How to Use NPM packages in vanilla JS without HTML file
How to Use NPM packages in vanilla JS without HTML file

Time:10-30

I want to use NPM package in my index.js file without installing it with package manager, i don't have a HTML file, i only have index.js file which is executed with node index.js command when i have to use this file anywhere, so i can't use CDN. Is there any way i can use the package in my js file without installing it and without using CDN. Or is there any way we can require or import a package locally in js file.

CodePudding user response:

You can use the built-in require function to import all node.js modules.

const crypto = require("node:crypto");

CodePudding user response:

This package crypto is no longer supported and has been deprecated. To avoid malicious use, npm is hanging on to the package name.

It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in.

you can use it by : const crypto = require("crypto");

  • Related