You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.pypi.md
+34-6Lines changed: 34 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,15 @@ To install:
23
23
pip install nodejs-bin
24
24
```
25
25
26
+
You can specify the Node.js version to install with:
27
+
28
+
```shell
29
+
pip install nodejs-bin==<version>
30
+
31
+
# Example:
32
+
pip install nodejs-bin==16.15.1
33
+
```
34
+
26
35
To run Node.js from the command line, use:
27
36
28
37
```shell
@@ -33,21 +42,40 @@ node
33
42
34
43
`npm` and `npx` are also available as `python -m nodejs.npm` and `python -m nodejs.npx`.
35
44
36
-
To run Node.js from a Python program:
45
+
To run Node.js from a Python program and return the exit code:
37
46
38
47
```python
39
-
from nodejs import node, npm, npm
48
+
from nodejs import node, npm, npx
40
49
41
50
# Run Node.js and return the exit code.
42
-
node.run(['script.js', 'arg1', ...])
51
+
node.run(['script.js', 'arg1', ...], **kwargs)
43
52
44
53
# Run npm and return the exit code.
45
-
npm.run(['command', 'arg1', ...])
54
+
npm.run(['command', 'arg1', ...], **kwargs)
46
55
47
56
# Run npx and return the exit code.
48
-
npx.run(['command', 'arg1', ...])
57
+
npx.run(['command', 'arg1', ...], **kwargs)
58
+
```
59
+
60
+
The `run(args, **kwargs)` functions wrap [`subprocess.call()`](https://docs.python.org/3/library/subprocess.html#subprocess.call), passes though all `kwargs` and returns the exit code of the process.
61
+
62
+
Additionally, to start a Node.js process and return a `subprocess.Popen` object, you can use the `start(args, **kwargs)` functions:
The `start(args, **kwargs)` functions wrap [`subprocess.Popen()`](https://docs.python.org/3/library/subprocess.html#subprocess.Popen), passes though all `kwargs` and returns a [`Popen` object](https://docs.python.org/3/library/subprocess.html#popen-objects).
78
+
51
79
Alternatively use `sys.executable` to locate the Python binary to invoke. For example:
52
80
53
81
```python
@@ -56,7 +84,7 @@ import sys, subprocess
56
84
subprocess.call([sys.executable, "-m", "nodejs"])
57
85
```
58
86
59
-
Additionally, the standard `node`, `npm` and `npx` commands are also added to your Python environment's `bin` directory. This is usually on your `PATH` and so they should be available in your shell environment.
87
+
Finally, the standard `node`, `npm` and `npx` commands are also added to your Python environment's `bin` directory. This is usually on your `PATH` and so they should be available in your shell environment.
0 commit comments