A lightweight Express.js server for serving Iconify icons.
This project provides a simple and efficient way to serve Iconify icons using Express.js. It allows you to easily integrate Iconify icons into your web applications.
Install the express-iconify, run the following command:
# npm
npm install express-iconify
# yarn
yarn add express-iconify
# pnpm
pnpm add express-iconifyYou can import the Iconify server into your external Express project and mount it using the mountIconify function.
mountIconify is a function that mounts the Iconify server to your Express application. It takes two arguments:
app: An Express application instance.option: An optional options object that configures the behavior ofmountIconify.
path: The path to mount the iconify app, default is/iconify.cache: Whether to cache the icon data in memory. Default istrue.cacheMaxSize: The maximum size of the cache. Default is10000.enableLastModified: Whether to set theLast-Modifiedheader. Default istrue.enableCORS: Whether to enable CORS. Default isfalse.download: Whether to serve the icon as an attachment. Default isfalse.
The mountIconify function returns the Express application instance with the Iconify server mounted.
import express from "express";
import { mountIconify } from "express-iconify";
const app = express();
// Mount Iconify server to /icons path
mountIconify(app, { path: "/icons" });
app.listen(3000, () => {
console.log("Server started on port 3000");
});In this example, the Iconify server is mounted to the /icons path.
Install the dependencies first, run the following command:
npm installTo build and start the server, run the following command:
npm build
npm startThe server will listen on port 80 by default. You can change the port by setting the PORT environment variable.
The server provides a single API endpoint for serving icons:
GET /:iconSet/:iconNameiconSet: The name of the Iconify icon set (e.g. "mdi")iconName: The name of the icon (e.g. "account")
You can also specify additional query parameters to customize the icon:
width: The width of the icon (e.g. "24")height: The height of the icon (e.g. "24")color: The color of the icon (e.g. "#333")rotate: The rotation of the icon (e.g. "90deg")flip: The flip direction of the icon (e.g. "horizontal")box: Whether to add a bounding box around the icon (e.g. "true")download: Whether to download the icon as an attachment (e.g. "true")
Example:
GET /:iconSet/:iconName?width=24&height=24&color=%23333&rotate=90degThis would retrieve an icon with a width and height of 24 pixels, a color of #333, and rotated 90 degrees.
This project is licensed under the MIT License.