It sounds like you want to create a single executable artifact which requires no server-side configuration or setup to run.
There are a few options for this. You're probably looking for a Javascript bundler, like Rollup, Parcel or Webpack. Webpack is the most widely used, but also generally the most difficult to configure.
Using bundlers
Parcel
Install Parcel with npm i -g parcel
, then, add this to your package.json:
"main": "dist/index.js",
"targets": {
"main": {
"includeNodeModules": true
},
},
Then run parcel build index.js
. That's it!
I've added a simple demo on GitHub.
Webpack
There are a number of great answers on this SO question.
Bundler caveats
Many node packages come with binary/native addons. For example, Cypress downloads and installs a browser. Any package which uses native addons will not work with a bundler, as the bundler is unable to add the binary files. These packages will still need to be installed.
Another option: building a binary
In the processes above, your output artifact is a single Javascript file. Instead of a Javascript file, you could also produce a binary file and thus alleviate the need to install the Node runtime. Check out pkg to do this. While pkg
is a fairly mature product, this is generally still considered an experimental technology, so perhaps not suited for a production environment. On the other hand, you shouldn't run into any problems with packages that include native addons. Read the documentation to see if it's appropriate for your use case.