npm install
npm start
Mac OS/Linux
$ DEBUG=myapp:* npm start
Windows
set DEBUG=myapp:* & npm start
Server is running on port 3001, you can visit the server by entering http://localhost:3001 in your browser.
Just enter node create_db
, it will create Databases ( development, testing, production )
By entering node create_tables
it will look for sequelize-models defined in models folder, and create them.
( The force : true attribute does override existing tables )
Route | HTTP-Method | Accepted body fields | Response |
---|---|---|---|
/users | GET | - | Returns an array with users |
/users/2 | GET | - | Returns a user object with Id 2 |
/users?sort=firstname&order=asc | GET | - | Returns an array with users sorted by firstname (order: ascending) |
/users?sort=id&order=desc | GET | - | Returns an array with users sorted by id (order: descending) |
/users?sort=username | GET | - | Returns an array with users sorted by username (default: ascending) |
/users | POST | "firstname" "lastname" "username" (unique) "photo" (blob) | The created user object |
/users/2 | DELETE | - | The new list of users excluding user with id 2 |
/users/2/?sort=id&order=desc | DELETE | - | The new list of users excluding user with id 2 and sorted by id (order: descending) |
/users/2/detail | DELETE | - | Empty Object |
/users/2/detail | PUT | "firstname" "lastname" "username" (unique) "photo" (blob) | The updated object with id 2 |
/users/3 | PUT | "firstname" "lastname" "username" "photo" (blob) | The whole list of users after update of specific object with id 3 |
/users/3?sort=id&order=desc | PUT | "firstname" "lastname" "username" "photo" (blob) | The whole list of users after update of specific object with id 3 and sorted by id (order: descending) |
PUT /users/3
PUT /users/3/detail
Its very simple, both will do the same they both update the record with the id 3, but they are giving back a different response. The first route should be used, when a list gets updated, because it will respond with the whole array of users after the update of user with id 3. The second route returns just the updated user object.
DELETE /users/3
DELETE /users/3/detail
The very same concept is implemented with DELETE. The first route, will give back all records of users after deleting the user with id 3. The second route, will give back a empty object and should be used when we don't need to update a list (for example in a detail page of all users)
.jpeg, .jpg, .png, .gif
All other file types which gets uploaded will result in a error called by multer (see also: https://github.com/EdwinBoos/fullstack-web/blob/master/routes/users.js#L10)