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.
Asked
Active
Viewed 332 times
-1

Nasyx Nadeem
- 241
- 2
- 12
-
[`crypto` is a node core module](https://nodejs.org/api/crypto.html). – CherryDT Oct 29 '22 at 16:48
-
Why are you not willing to use NPM? What objective are you trying to accomplish? The feels like an XY question that doesn't really explain the real objective/problem here. You can copy modules from NPM and just include them in your own source. Not sure why you'd do that since you orphan that code from future bug fixes and improvements, but you can. – jfriend00 Oct 29 '22 at 18:34
2 Answers
1
You can use the built-in require
function to import all node.js modules.
const crypto = require("node:crypto");

codingtuba
- 366
- 2
- 13
-
-
1
-
as i already said in the question, i Dont want to install them using nom – Nasyx Nadeem Oct 29 '22 at 16:54
-
1@NasyxNadeem then you'll be stuck to using the default packages. There's no work-around for that. – codingtuba Oct 29 '22 at 16:55
-
1although, you could use something like vite to compile your modules if you don't want to ship them to production. – codingtuba Oct 29 '22 at 16:57
1
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");

Amine Deflaoui
- 13
- 4
-
-
1check out this : https://stackoverflow.com/questions/15035786/download-source-from-npm-without-installing-it#:~:text=If%20you%20haven't%20installed,code%20archive%20and%20download%20it. – Amine Deflaoui Oct 29 '22 at 16:56