- Download Node package manager for your OS - link
- Download and unpack the code repository in an empty directory
- Goto base directory which has package.json file
- Run commands:
npm install- to install all the node dependenciesnpm run prod- to build and run the server
- Once the server is up, the application will be available on port 3000 on localhost
- Goto http://localhost:3000/api-docs - to check swagger documentation of the APIs.
- You may use HTTP clients like - Postman, Fiddler, SOAPUI, curl or your favorite browser extension for testing
The backend service should allow for:
- Listing availabe images
- Seeing image metadata (title, timestamp, canonical URL)
- Uploading and downloading images
User authentication is not in scope
- Allows querying metadata for all the images on the server (GET on /images)
- Allows uploading an image from a client (POST on /images)
- Allows downloading an image using the canonical url from previous operations (GET on /images/:id)
- Allows deleting an image using canonical url from previous operations (DELETE on /images/:id)
- Nodejs, Expressjs, Typescript
- Multer - to allow uploading and downloading of files to/from server
- lokijs - filesystem based database to store metadata of the images loaded
- swagger - to document and test APIs exposed
- Does not allow for uploading/downloading multiple images
- No provision for filter when querying the images
- Idempotent PUT/POST is not supported - that means, if you (or your browser) uploads the same image twice, there will be duplicate entries for that image on server side
- A very limited number of image extension supported viz. jpg/jpeg/png/gif
- This is a very basic service, to be hosted on single host with limited to no provision for security. But this can serve as a boilerplate to an application with better features for security, scalability and maintenance.
- To upload images, client has capability to send the file using multipart/form-data as content type
- There is no need for updating a photo at a given id - this can be achieved using combination of DELETE and POST
- To download an image
- The client with perform GET for all images
- Choose the image to download
- Use the canonical URL returned in the output to GET the image by Id
The last point seems like a design. The assumption here is that the client does not have a way to generate a unique ID, which can be later used to query the image.
- image-server.ts will have code to initialize and configure the server
- image-model.ts will have the data model to capture for input and output
- image-controller.ts will act as a router for exposing the endpoints for various operations
- dbutils.ts will have utilities to store image meta data in DB and image file in file system
- lokisjs will be used to store metadata - it has provision to persist the data in filesystem in JSON format
- Multer will be used store the uploaded image into server filesystem
- node module 'fs' will be used for allowing lokijs and multer to access the local file system
- lokijs - file system adapter - https://rawgit.com/techfort/LokiJS/master/jsdoc/LokiFsAdapter.html
- Multer to upload files - https://www.npmjs.com/package/multer
- Basics of Node, Express and Typescript -https://itnext.io/building-restful-web-apis-with-node-js-express-mongodb-and-typescript-part-1-2-195bdaf129cf