Package: nodejs-bin
Node.js PyPI distributionNode.jsis an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser.Thenodejs-binPython package redistributes Node.js so that it can be used as a dependency of Python projects. Withnodejs-binyou can callnodejs,npmandnpxfrom both thecommand lineand aPython API.Note: this is an unofficial Node.js distribution.This is intended for use within Python virtual environments and containers, it should probably not be used for global installation.This PyPI distribution is provided byhttps://github.com/samwillis/nodejs-pypi.InstallTo install:pipinstallnodejs-binBy default the command linenode,npmandnpxcommands are not installed to prevent collisions with already installed Node.js versions. To install them:pipinstall'nodejs-bin[cmd]'You can specify the Node.js version to install with:pipinstallnodejs-bin==<version># Example:pipinstallnodejs-bin==16.15.1Command Line UsageTo run Node.js from the command line, use:python-mnodejsnpmandnpxare also available asnodejs.npmandnodejs.npx:python-mnodejs.npm
python-mnodejs.npxIf you installed the optional command line commands withpip install 'nodejs-bin[cmd]'(see above), you can use them directly from the command line as you would normally with Node.js:node
npm
npxPython API Usagenode-binhas a simple Python API that wraps the Node.js command line with thePythonsubprocess.Fornode,npmandnpxthere are.call(),.run()and.Popen()methods that match the equivalentsubprocessmethods.To run Node.js from a Python program and return the exit code:fromnodejsimportnode,npm,npx# Run Node.js and return the exit code.node.call(['script.js','arg1',...],**kwargs)# Run npm and return the exit code.npm.call(['command','arg1',...],**kwargs)# Run npx and return the exit code.npx.call(['command','arg1',...],**kwargs)Thecall(args, **kwargs)functions wrapsubprocess.call(), passes though allkwargsand returns the exit code of the process.To run Node.js from a Python program and return aCompletedProcessobject:fromnodejsimportnode,npm,npx# Run Node.js and return the exit code.node.run(['script.js','arg1',...],**kwargs)# Run npm and return the exit code.npm.run(['command','arg1',...],**kwargs)# Run npx and return the exit code.npx.run(['command','arg1',...],**kwargs)Therun(args, **kwargs)functions wrapsubprocess.run(), passes though allkwargsand returns aCompletedProcess.Additionally, to start a Node.js process and return asubprocess.Popenobject, you can use thePopen(args, **kwargs)functions:fromnodejsimportnode,npm,npx# Start Node.js and return the Popen object.node_process=node.Popen(['script.js','arg1',...],**kwargs)# Start npm and return the Popen object.npm_process=npm.Popen(['command','arg1',...],**kwargs)# Start npx and return the Popen object.npx_process=npx.Popen(['command','arg1',...],**kwargs)ThePopen(args, **kwargs)functions wrapsubprocess.Popen(), passes though allkwargsand returns aPopenobject.Thenodejs.nodeapi is also available asnodejs.runandnodejs.callandnodejs.Popen.Finally, there are a number of convenient attributes on thenodejsmodule:nodejs.node_version: the version of Node.js that is installed.nodejs.path: the path to the Node.js executable.Versionsnodejs-bin offers Node.jsCurrentandLTS(long-term support) versions. See theNode.js Documentationfor more information.The full list of versions is available on PyPI is here:https://pypi.org/project/nodejs-bin/#historyLicenseTheNode.js license.