A task that was given to me by a company to apply for a position.
npm install
npm start
- PORT - sets port on witch server to be listening on. Default 3000
- HOST - sets host on witch server will be working on. Default localhost
- PG_CONNECTION_URL - postgres database connection url (https://jdbc.postgresql.org/documentation/80/connect.html)
- DOTENV_PATH - patch to .env file (https://www.npmjs.com/package/dotenv) [You can set env variables throught this file]. When runing tests you can set same variable to point to different file for tests.
- NODE_ENV - node environment. When running on production needs to be set to "production". In other cases provides extra information (stack trace) on error responses.
GET /user
- replies with 200 status code and json all the users found in tableGET /user/:login
- replies with 200 and json user if found or error 'No such user' otherwisePOST /user
- creates new user. Body parameters:login
,email
,name
andage
. Relies with 200 and json new user created or error if login already taken by other user.PUT /user/:login
- modifies the existing user. Body parameters:email
,name
andage
. Replies with 200 and json modified user if found or error 'No such user' otherwise- Any unmached rout - replies with 404 and json body with error
Not Found
. - If error occurs - replies with 500 and json body with error message.
- Body can be send with Content-Type:
application/json
orapplication/x-www-form-urlencoded