Skip to content

Proxy server for image optimization on Node.JS use (fastify, axios, sharp)

License

Notifications You must be signed in to change notification settings

AntonLukichev/node-imgoptimize

Repository files navigation

node-imgoptimize

Build Status Maintainability Test Coverage

js-standard-style License

release NPM downloads Known Vulnerabilities Greenkeeper badge

Proxy server for image optimization on Node.JS use (fastify, axios, sharp) Automatic recognition of browser support formats WebP

Install

Yarn

yarn add node-imgoptimize
git clone https://github.com/AntonLukichev/node-imgoptimize.git
yarn install

NPM

npm install node-imgoptimize --save
git clone https://github.com/AntonLukichev/node-imgoptimize.git
npm install

Requires node >= 8.0, but I recommended use >= 10.0 LTS

Install as service on Ubuntu

Heroku

example https://node-imgoptimize.herokuapp.com/

Install on Heroku
Deploy to Heroku

use Docker

$ git clone https://github.com/AntonLukichev/node-imgoptimize.git
$ cd ./node-imgoptimize
$ docker build -t node-imgoptimize .
$ docker run -it --rm -p 3000:3000 -e NODE_ENV=production node-imgoptimize
$ git clone https://github.com/AntonLukichev/node-imgoptimize.git
$ cd ./node-imgoptimize
$ docker-compose build
$ docker-compose up

see tips for Docker

Example Usage

{url}?w=500&q=80

support parameters (after "?"):

w - image width;
h - image height;
q - image quality, 80 recommended for JPEG and WebP;
fm - image format, list in config.js and default jpeg or webp (if browser supports it);

Example config

Edit defaults config for you need (automatically created after the first run)

./config/config.js

./config/server.js

ToDo

v0.2.0:

  • generate source url with original request parameters
  • caching original file
  • support a large number of files

v0.3.0:

  • add multiple path URI
  • add JPEG and WebP options

v0.4.0:

  • custom log level
  • documentation API in Swagger
  • add docker
  • support Heroku

v0.5.0:

  • add monitoring errors sentry.io
  • default favicon
  • add tests

v1.0.0:

  • migrate Typescript and NestJS

I plan to implement in the future:

  • add CORS
  • expand API
  • add options Low Quality Image Placeholders (LQIP)
  • add Client Hints (headers DPR, Viewport-Width, Width) for support Chrome, Opera, Android Chrome
  • add support another formats (GIF, PNG, SVG...)
  • divide the functionality into modules up to version 1.0.0
  • support PAAS (Heroku, Zeit, Nanobox...)
  • add support HTTP2
  • add security protection
  • add support redis/mongo for cache info
  • add image operations (rotate, blur, normalise...)

Lazy loading

If you'd like to lazy load images, I recommend using lazysizes.

FAQ

How add custom favicon

Simple copy your favicon.ico file in root directory project

Security

Node.js Security Checklist

Production Best Practices: Security

Contributing

See the CONTRIBUTING file here

License

MIT

Copyright (c) Anton Lukichev