This project is an API that allows you to place images into your frontend with the size set via URL parameters and serve properly scaled versions of your images to reduce page load size. It is built with Node.js and uses best practices such as TypeScript, unit testing, linting, and formatting to ensure scalable and maintainable code. The API can be used for rapid prototyping or as a library for serving stored images in various sizes. It provides the building blocks for handling image processing in an enterprise-level solution.
To get started with this project, follow these steps:
-
Make sure that you have Node.js and npm installed on your system. If you don't already have them, you can download and install them from the official Node.js website
-
Clone the repository:
git clone https://github.com/RogerA11/Image-Processing-API.git -
Navigate to the root directory of the project:
cd Image-Processing-API
-
Open a terminal window and navigate to the root directory of your project.
-
Run the following command to install the dependencies listed in the package.json file:
npm install
This will install all the packages listed in the dependencies and devDependencies sections of the package.json file. The packages will be downloaded from npm and placed in a node_modules directory within the project.
These packages are required to run the project.
express: A web framework for Node.jssharp: An image processing librarysupertest: A library for testing HTTP APIstypescript: A typed superset of JavaScript
Installation example:
-
Open a terminal window and navigate to the root directory of your project.
-
Run the following command.
npm i express
The devDependencies section in the package.json script lists the packages that are used for development purposes.
Instructions for using the project.
-
To run the project, open the terminal and use the
startscript:npm run startor
node build/main -
Follow the given link:
http://localhost:3000 -
Navigate to the resize API and include arguments for relevant query parameters, like the example below:
http://localhost:3000/resize?filename=fjord&width=255&height=300-
filename argument can include:
['encenadaport', 'fjord', 'icelandwaterfall', 'palmtunnel', 'santamonica']
-
Both width and height arguments can not be negative.
-
-
Running the request should result in a processed image output like the one below:
-
This resized image will be stored in the
/assets/thumbdirectory as fjord_255_300_thumb.jpg
Other scripts that are available include:
format: Formats the code using Prettierlint: Lints the code using ESLintjasmine: Runs the Jasmine testsbuild: Transpiles the TypeScript code into JavaScripttest: Builds the code and runs the Jasmine tests
Running script example:
-
Open a terminal window and navigate to the root directory of your project.
-
Run the following command.
npm run format
