An awesome image processing api built with Node.js, TypeScript & Sharp.
- Node.js & Express for building the API server.
- Handlebars as the default view engine.
- Sharp for image processing.
- Bootstrap for styling.
-
Install dependencies
npm install
. -
Run
npm run build
to create a production build. -
Rename
.env.example
to.env
file and provide a value forPORT
. -
Run
npm run start
to start the server. -
Open you browser and navigate to
http://localhost:<PORT>/
to see the resizer page.
The tests are written in jasmine. To run the tests: npm run build && npm run test
.
- Express App Tests Suit
- Serve Favicon
- Serve Static Files
- Use Handlebars as view engine
- Main Router Tests Suit
- Return 200
- Return html document
- Image Router Tests Suit
GET /api/{resize | convert}
Requests- Return 400 for empty query string
- Return 422 for invalid query string
- Return 404 if image does not exist
- Return 200 with resized image for valid query string
- Return 200 with resized image for the same query string
- Image Helper Tests Suit
imageExists
method- Return file name with extension if file exists in directory
- Return "File does not exist" if file does not exist in directory
getAllImages
method- Return a list of 5 images
resolveImageDirectoryPath
method- Return directory full path as string
resolveToSourceAndTarget
method- Return an object with source & target keys
- Sharp Service Tests Suit
resize
service- Should delete the resized file if exists & create a new fresh one
- Return "File does not exist" if file does not exist in directory
convert
service- Should delete the resized file if exists & create a new fresh one
dev
: to start the development serverstart
: to start the production servertest
: to run jasmine tests on production buildlint
: to run eslint on the project's typescript filesclean
: to remove old builds before building a new onelint:fix
: to fix issues identified by eslintpostbuild
: to copy views folder to the production build folder.format
: to run prettier on the project's typescript files
-
/api/resize
to resize an image with a given query string for example?filename=fjord&width=200&height=600
. -
/api/convert
to convert an image with a given query string to the given format for example?filename=fjord&format=png
. Supported conversion types are[jpg, png, avif, jpeg, webp]
. -
/{full | thumbs}/{image_name}
to serve static image files for example/full/fjord.jpg
.