0
# Node.js Installation
1
2
Node.js version management and installation functionality including downloading prebuilt binaries, building from source code, and copying installations with platform-specific optimizations.
3
4
## Capabilities
5
6
### Node.js Installation
7
8
Primary function for installing Node.js in a virtual environment, supporting both prebuilt binaries and source compilation.
9
10
```python { .api }
11
def install_node(env_dir, src_dir, args):
12
"""
13
Install Node.js in the virtual environment.
14
15
Parameters:
16
env_dir (str): Environment directory path
17
src_dir (str): Source/download directory path
18
args (argparse.Namespace): Configuration arguments
19
20
Installs Node.js using the method specified in args:
21
- Prebuilt binaries (default, faster)
22
- Source compilation (slower, more compatible)
23
- System Node.js (symlink to existing installation)
24
25
Handles platform-specific installation procedures and
26
configures the Node.js installation for the environment.
27
"""
28
```
29
30
### Wrapped Node.js Installation
31
32
Wrapper function for Node.js installation with enhanced error handling and logging.
33
34
```python { .api }
35
def install_node_wrapped(env_dir, src_dir, args):
36
"""
37
Install Node.js with enhanced error handling and progress reporting.
38
39
Parameters:
40
env_dir (str): Environment directory path
41
src_dir (str): Source/download directory path
42
args (argparse.Namespace): Configuration arguments
43
44
Provides a wrapper around install_node with:
45
- Enhanced error reporting and recovery
46
- Progress indication during installation
47
- Cleanup on installation failure
48
- Validation of successful installation
49
"""
50
```
51
52
### Prebuilt Binary Installation
53
54
Copies Node.js from prebuilt binary distributions for fast installation.
55
56
```python { .api }
57
def copy_node_from_prebuilt(env_dir, src_dir, node_version):
58
"""
59
Copy Node.js from prebuilt binary distribution.
60
61
Parameters:
62
env_dir (str): Target environment directory
63
src_dir (str): Directory containing downloaded binaries
64
node_version (str): Node.js version being installed
65
66
Extracts and copies prebuilt Node.js binaries to the environment.
67
Handles platform-specific binary formats and directory structures.
68
Configures executable permissions and creates necessary symlinks.
69
"""
70
```
71
72
### Source Code Compilation
73
74
Builds Node.js from source code with custom compilation options.
75
76
```python { .api }
77
def build_node_from_src(env_dir, src_dir, node_src_dir, args):
78
"""
79
Build Node.js from source code.
80
81
Parameters:
82
env_dir (str): Target environment directory
83
src_dir (str): Source download directory
84
node_src_dir (str): Node.js source code directory
85
args (argparse.Namespace): Build configuration arguments
86
87
Compiles Node.js from source with options:
88
- Custom compilation flags
89
- SSL support configuration (--without-ssl)
90
- Parallel build jobs (--jobs)
91
- Platform-specific optimizations
92
93
Provides more control and compatibility at the cost of build time.
94
"""
95
```
96
97
### URL Generation
98
99
Utility functions for generating download URLs for Node.js binaries and source code.
100
101
```python { .api }
102
def get_node_bin_url(version):
103
"""
104
Get download URL for Node.js prebuilt binary.
105
106
Parameters:
107
version (str): Node.js version (e.g., '16.20.0')
108
109
Returns:
110
str: Download URL for platform-appropriate binary
111
112
Generates URLs based on:
113
- Platform detection (Linux, macOS, Windows)
114
- Architecture detection (x64, arm64, etc.)
115
- Special handling for musl and RISC-V systems
116
"""
117
118
def get_node_src_url(version):
119
"""
120
Get download URL for Node.js source code.
121
122
Parameters:
123
version (str): Node.js version
124
125
Returns:
126
str: Download URL for source tarball
127
"""
128
129
def get_root_url(version_str):
130
"""
131
Get root URL for Node.js downloads based on version.
132
133
Parameters:
134
version_str (str): Node.js version string
135
136
Returns:
137
str: Base URL for Node.js downloads
138
139
Handles different download sources and mirrors.
140
"""
141
142
def get_root_url(version_str):
143
"""
144
Get root URL for Node.js downloads based on version.
145
146
Parameters:
147
version_str (str): Node.js version string
148
149
Returns:
150
str: Base URL for Node.js downloads
151
152
Adjusts URL structure based on Node.js version (pre/post 0.5).
153
Handles different download sources and mirrors.
154
"""
155
156
def get_node_src_url(version):
157
"""
158
Get download URL for Node.js source code.
159
160
Parameters:
161
version (str): Node.js version
162
163
Returns:
164
str: Download URL for source tarball
165
166
Constructs complete URL for downloading Node.js source code
167
tarball based on version and root URL structure.
168
"""
169
```
170
171
### Source Download
172
173
Downloads Node.js source code or prebuilt binaries from remote repositories.
174
175
```python { .api }
176
def download_node_src(node_url, src_dir, args):
177
"""
178
Download Node.js source or binary distribution.
179
180
Parameters:
181
node_url (str): Download URL
182
src_dir (str): Target download directory
183
args (argparse.Namespace): Configuration arguments
184
185
Downloads and extracts Node.js distributions with:
186
- Progress reporting
187
- Retry logic for failed downloads
188
- Checksum verification (when available)
189
- Proxy support
190
"""
191
```
192
193
## Usage Examples
194
195
### Install Latest Node.js
196
197
```python
198
import nodeenv
199
from argparse import Namespace
200
201
args = Namespace(
202
node='latest',
203
source=False, # Use prebuilt binaries
204
without_ssl=False,
205
jobs='2'
206
)
207
208
nodeenv.install_node('/path/to/env', '/tmp/nodeenv-src', args)
209
```
210
211
### Build from Source with Custom Options
212
213
```python
214
import nodeenv
215
from argparse import Namespace
216
217
args = Namespace(
218
node='16.20.0',
219
source=True, # Build from source
220
without_ssl=True, # Disable SSL
221
jobs='4' # Use 4 parallel jobs
222
)
223
224
nodeenv.install_node('/path/to/env', '/tmp/nodeenv-src', args)
225
```