0
# Node.js API
1
2
The Material Design Icons package provides a simple Node.js API for programmatic access to asset file paths.
3
4
## Capabilities
5
6
### STATIC_PATH Constant
7
8
Provides the absolute path to the package directory containing all icon assets.
9
10
```javascript { .api }
11
/**
12
* Path to the package directory containing all icon assets
13
* @type {string}
14
*/
15
const STATIC_PATH: string;
16
```
17
18
**Usage Examples:**
19
20
```javascript
21
const { STATIC_PATH } = require("material-design-icons");
22
const path = require("path");
23
24
// Build path to a specific PNG icon
25
const iconPath = path.join(
26
STATIC_PATH,
27
"action",
28
"1x_web",
29
"ic_3d_rotation_black_24dp.png"
30
);
31
32
// Build path to SVG icon
33
const svgPath = path.join(
34
STATIC_PATH,
35
"navigation",
36
"svg",
37
"production",
38
"ic_arrow_back_24px.svg"
39
);
40
41
// Build path to web font
42
const fontPath = path.join(
43
STATIC_PATH,
44
"iconfont",
45
"MaterialIcons-Regular.woff2"
46
);
47
48
console.log("Icon path:", iconPath);
49
console.log("SVG path:", svgPath);
50
console.log("Font path:", fontPath);
51
```
52
53
## File Structure Patterns
54
55
The package follows consistent directory patterns for all asset types:
56
57
### PNG Assets
58
```
59
${STATIC_PATH}/{category}/{density}/{filename}
60
```
61
62
Where:
63
- `{category}` is one of: action, alert, av, communication, content, device, editor, file, hardware, image, maps, navigation, notification, places, social, toggle
64
- `{density}` is one of: 1x_web, 2x_web, drawable-hdpi, drawable-mdpi, drawable-xhdpi, drawable-xxhdpi, drawable-xxxhdpi
65
- `{filename}` follows pattern: `ic_{icon_name}_{color}_{size}dp.png`
66
67
### SVG Assets
68
```
69
${STATIC_PATH}/{category}/svg/production/ic_{icon_name}_{size}px.svg
70
```
71
72
### iOS Assets
73
```
74
${STATIC_PATH}/{category}/ios/{filename}
75
```
76
77
### Web Fonts
78
```
79
${STATIC_PATH}/iconfont/MaterialIcons-Regular.{ext}
80
```
81
82
Where `{ext}` is one of: eot, svg, ttf, woff, woff2
83
84
## Integration Examples
85
86
### Express.js Static Serving
87
88
```javascript
89
const express = require("express");
90
const { STATIC_PATH } = require("material-design-icons");
91
const app = express();
92
93
// Serve Material Design Icons assets
94
app.use("/icons", express.static(STATIC_PATH));
95
96
// Now icons are available at:
97
// /icons/action/1x_web/ic_3d_rotation_black_24dp.png
98
// /icons/iconfont/MaterialIcons-Regular.woff2
99
```
100
101
### Webpack Asset Resolution
102
103
```javascript
104
const { STATIC_PATH } = require("material-design-icons");
105
const path = require("path");
106
107
module.exports = {
108
resolve: {
109
alias: {
110
"material-icons": STATIC_PATH
111
}
112
}
113
};
114
115
// In your code:
116
// import iconUrl from "material-icons/action/svg/production/ic_home_24px.svg";
117
```
118
119
### Build Tool Integration
120
121
```javascript
122
const { STATIC_PATH } = require("material-design-icons");
123
const fs = require("fs");
124
const path = require("path");
125
126
// Copy specific icons to build directory
127
const iconsNeeded = [
128
"action/svg/production/ic_home_24px.svg",
129
"navigation/svg/production/ic_menu_24px.svg"
130
];
131
132
iconsNeeded.forEach(iconPath => {
133
const src = path.join(STATIC_PATH, iconPath);
134
const dest = path.join("./build/icons", path.basename(iconPath));
135
fs.copyFileSync(src, dest);
136
});
137
```