https://github.com/dbtek/express-svg-convert
Straightforward svg convert api built on express.
https://github.com/dbtek/express-svg-convert
api converter express js node svg
Last synced: about 1 month ago
JSON representation
Straightforward svg convert api built on express.
- Host: GitHub
- URL: https://github.com/dbtek/express-svg-convert
- Owner: dbtek
- License: mit
- Created: 2016-12-27T14:14:29.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T17:43:02.000Z (over 3 years ago)
- Last Synced: 2025-12-12T21:35:30.134Z (6 months ago)
- Topics: api, converter, express, js, node, svg
- Language: JavaScript
- Size: 878 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
express-svg-convert
===
A straightforward express server that converts multipart/form-data svg files to pdf or png files.
Uses [librsvg](https://npmjs.com/package/librsvg), [express](https://npmjs.com/package/express), [express-fileupload](https://npmjs.com/package/express-fileupload).
## Run with Docker
```bash
$ docker run -p 8001:8001 -e SVG_CONVERT_API_KEY="secret-api-key" --name svgconverter -it dbtek/express-svg-convert
```
## Development
### Prerequisites
On macOs:
```bash
$ brew install cairo librsvg
```
### Install
- Download or clone repo.
- cd into downloaded & extracted folder
```bash
$ npm install
```
### Run
```bash
$ node .
# or
$ npm start
```
#### Exposed end points
- `/sample` : Converts bundled sample.svg
- `/api/convert`: Convert api.
### Params
Supported params are: format, scale.
> `http://localhost:8081/api/convert?format=[png|pdf]&scale=[number]`
#### Custom Port
```bash
$ export SVG_CONVERT_PORT=8001
```
#### Api Key
```bash
$ export SVG_CONVERT_API_KEY=secret-api-key
```
### Usage
Sample usage in browser:
```js
var svg = `
image/svg+xml
`
var formData = new FormData()
formData.append('svg', new Blob([svg]))
fetch(':secret-api-key@http://localhost:8081/api/convert', {
method: 'POST',
body: formData
})
.then(data => {
console.log(data)
})
.catch(err => console.log(err))
```