npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

express-sharp-server

v0.0.5

Published

express-sharp-server is a middleware that implements a restful image server based on node-sharp

Downloads

8

Readme

express-sharp-server

Build Status Coverage Status Known Vulnerabilities

express-sharp-server is a middleware that offers a restful image server based on node-sharp.

npm install express-sharp-server

express-sharp-server is an evolving express middleware to implement an easy-to-use image server, with a focus on extraction of image parts. The goal is to provide all prominent functions of the node-sharp library in a express middleware.

Server

const express = require('express');
const image = require('express-sharp-server');

const server = express();

// express-sharp-server expects at least a data folder 
// where the image data can be stored.

server.use(image({
    data_dir: '/data/'
}));

server.listen(8080);

express-sharp-server supports running in a node cluster enviroment, which improves the performance considerably. See cluster.

Options

The following options can be set:

| Parameter | Description | |----------- |----------- | | base_route | The base_route is used to configure the endpoint, where the middleware listen. Defaults to '/'. | | base_url | The base_url is a prefix for the image urls generated in the json responce _links.self.href useful if the server is behind a proxy. Defaults to '/'. | | data_dir | The data_dir is used to save the upload and cache files. If upload_dir is not set, data_dir + '/upload/' is created for uploads, If cache_dir is not set, data_dir + '/cache/' is used. Mandatory, if upload_dir or cache_dir is not set. | | upload_dir | The directory where the image uploads to be saved. Optional. | | cache_dir | The directory where the image cache to be saved. Optional. | | logger | optional, a instance to winston logger. Optional. |

Basic Usage

First of all, images can be uploaded.

curl -F "[email protected]" http://localhost:8080

In addition, it is possible to reference an image from another server by sending a image url:

{
    "_links": {
        "origin": {
            "href": "https://upload.wikimedia.org/wikipedia/commons/d/d7/Elefantes_Gustavo_Gerdel.jpg"
        }
    }
}
curl --header "Content-Type: application/json" \
  --request POST \
  --data '{ "_links": { "origin": { "href": "https://upload.wikimedia.org/wikipedia/commons/d/d7/Elefantes_Gustavo_Gerdel.jpg" } } }' \
  http://localhost:8080/

In any case, the server responds with the following payload in json.

{
    "metadata": {
        "width": 1200,
        "height": 800,
        "channels": 3,
        "density": 300,
        "mimetype": "image/jpeg",
        "format": "jpeg"
    },
    "created": {
        "datetime": "2019-01-04T23:45:30.873Z"
    },
    "_links": {
        "self": {
            "href": "/0c97f820639ecbbbba0255ceb7a5f962"
        }
    }
}

The image is now stored on the server and can now be retrieved via the url specified as _links.self.href

curl http://localhost:8080/0c97f820639ecbbbba0255ceb7a5f962

The underlying information on the server can be queried if in addition an "Accept: application/json" header is sent.

curl --header "Accept: application/json" \
    http://localhost:8080/0c97f820639ecbbbba0255ceb7a5f962

It is possible to store userdata to an image resource, see userdata.

Features

The following parameter can be mixed.

| Parameter | Comment | |----------- |----------- | | width | The width of the image, The aspect ratio is retained if no height parameter is present. | | height | The height of the image, The aspect ratio is retained if no width parameter is present. | | polygon | Can be used to extract a partion of the image. If the Polygon is not recangular, the oferlapping parts of the source image are masked with a uniform color. | | rotation | Rotation of the extracted image. | | grayscale | Remove color from the image. |

See examples for more information.

Todos

The node-sharp library has far more features, this middleware currently offers. In the future, more of its functionality will be implemented in express-sharp-server.

The Caching functionality, even if it supports worker, ist very simple and need to be improved in future.

Finally, there is no method to remove a image resource, or list all available resources. This is the next functionality to implement.

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

Licensing

Copyright 2019 Marcel Bretschneider.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.