Node.js® Package Deployment
Deploying a TypeScript or JavaScript module
To deploy a TypeScript or JavaScript
module, it must be copied with all sub-folders from the development to the
production environment. While an internet connection is necessary for development,
it is not required in the production environment, because all required dependencies
will be contained in the sub-folder node_modules
.
For TypeScript modules, it is important that all
.ts
files have been compiled to JavaScript and the corresponding .js
files are copied as well.
While developing a TypeScript or JavaScript module, a lot of packages are added to
node_modules
that are only needed for development, but not for
production (e. g. TypeScript compiler, ESLint). To reduce
the size of the module before it is distributed to the production environment, the
following commands can be used:
npm prune --production
This command removes all modules that are only needed for development (which are
listed in package.json
in the section
"devDependencies"
) and their dependencies. Since this removes packages
that will be required for further development, it is recommended to copy the module
before executing this command. Alternatively, you can run npm install
again at any time to reinstall all modules that were removed with this command.
npm prune
This command removes all modules that are neither required for production or development and their dependencies. This is useful when packages where installed that later became replaced by something else or turned out to be not needed at all.