Part of Udacity's Full-Stack nanodegree
NOTE While using hex colors make sure to encode #
as %23
since the hash symbol is used by the browser!
- To install required dependencies run
npm i
oryarn
- Create a new
.env
file and set variables written in.env.template
PORT
is the part number to be used by the serverIMAGES_DIR
is the directory name to get images from, defaults to "images"CACHE_DIR
is the directory name to get cached images from, defaults to "cache"
npm run dev
oryarn dev
starts a development server on the port in the.env
filenpm run build
oryarn build
builds the project for production inbuild
directorynpm run jasmine
oryarn jasmine
runs jasmine for unit tesingnpm run test
oryarn test
builds the project then runs the unit testsnpm run lint
oryarn lint
runs eslint to check for style or code issues.npm run lint:fix
oryarn lint:fix
similar to the previous but tries to fix all auto fixable issuesnpm run prettier
oryarn prettier
runs prettier to improve & fix writing stylenpm run start
oryarn start
runs the production build using the.env
file (need the project to be build beforehand)
After starting the server you can check the functionality of the project as detailed below
- Send a
GET
request tohttp://localhost:${PORT}/placeholder?width={width}&height={height}
replacePORT
with your port number that is added in the.env
file & replace both{width}
&{height}
with your desired ints
GET http://localhost:8080/placeholder?width=250&height=250
A CSS supported color to be applied on the background of the placeholder image
GET http://localhost:8080/placeholder?width=250&height=250&bgColor=cornflowerblue
A CSS supported color to be applied on the text of the placeholder image
GET http://localhost:8080/placeholder?width=250&height=250&textColor=%23e5e5e5
A string containing the text to be in the image
GET http://localhost:8080/placeholder?width=250&height=250&textColor=%23e5e5e5&text=Hello, World!
- Send a
GET
request tohttp://localhost:${PORT}/resize?width={width}&height={height}&filename={filename}
replacePORT
with your port number that is added in the.env
file & replace both{width}
&{height}
with your desired ints, filename should be replaced with a file inside theIMAGES_DIR
added in the.env
file (along with the extension)
GET http://localhost:8080/resize?width=250&height=250&filename=scandanavia-01.jpeg
Instead of using the filesystem you can just enter a url of an image
GET http://localhost:8080/resize?width=250&height=250&url=https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png
If you wanted to fetch a png file but wants it to be compressed using webp or jpeg encoding you can pass the type
parameter with 3 possible values webp
, png
, jpeg
It compresses the file on the fly
GET http://localhost:8080/resize?width=250&height=250&filename=scandanavia-01.jpeg&type=webp