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
+22-1Lines changed: 22 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ Node.js PyPI distribution
5
5
6
6
The [node-js][pypi] Python package redistributes Node.js so that it can be used as a dependency of Python projects.
7
7
8
+
**This is intended for use within Python virtual environments and containers, it should not be used for global instillation.**
9
+
8
10
[zig]: https://nodejs.org/
9
11
[pypi]: https://pypi.org/project/node-js/
10
12
@@ -17,14 +19,33 @@ To run the Zig toolchain from the command line, use:
17
19
python -m nodejs
18
20
```
19
21
20
-
To run Node.js from a Python program, use `sys.executable` to locate the Python binary to invoke. For example:
22
+
`npm` and `npx` are also available as `python -m nodejs.npm` and `python -m nodejs.npx`.
23
+
24
+
To run Node.js from a Python program:
25
+
26
+
```python
27
+
from nodejs import node, npm, npm
28
+
29
+
# Run Node.js and return the exit code.
30
+
node.run(['script.js', 'arg1', ...])
31
+
32
+
# Run npm and return the exit code.
33
+
npm.run(['command', 'arg1', ...])
34
+
35
+
# Run npx and return the exit code.
36
+
npx.run(['command', 'arg1', ...])
37
+
```
38
+
39
+
Alternatively use `sys.executable` to locate the Python binary to invoke. For example:
21
40
22
41
```python
23
42
import sys, subprocess
24
43
25
44
subprocess.call([sys.executable, "-m", "nodejs"])
26
45
```
27
46
47
+
`node`, `npm` and `npx` 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