This is the code example for AvenueCode Node and Express Course.
npm install
This will install all the dependencies and grunt-cli (the last one as a global package).
###Dependencies
- NodeJS
- Express
- body-parser
- blanket
- bootstrap
- cookie-parser
- jsonwebtoken
- Grunt
- grunt-cli
- grunt-contrib-copy
- grunt-mocha-test
- grunt-nodemon
- Jquery
- Jquery-Cookie
- mocha
- mongoose
- should
- supertest
To run the server you just have to execute:
$ grunt serverExpress
After you have set up the server and executed $ grunt serverExpress
, you can access http://localhost:3000 and use
the interface to test responses and behavior. (This code is in 'serverExpress/public/index.html').
- '/users/?q=query' - GET - List of all users or search by name using query
- '/users/' - POST - Create user
- '/users/me' - GET - Get logged user
- '/users/me' - PUT - Update logged user profile
- '/users/:userId' - GET - Get user with given ID
- '/users/:userId' - DELETE - Delete user with given ID
- '/users/:userId/password' - PUT - Change user's password
All endpoints are authenticated/authorized, but creating user. This endpoint is public. And the endpoint to delete user is authorized only to a admin.
Authorization/Authentication is done using token, by JWT.
We are using mocha, supertest and should to do Unit Testing. We also added blanket as a coverage tool.
Obs.: Windows users BE WARNED! To execute the grunt test task you need to perform a change in the blanket lib. In the file node_modules/blanket/src/index.js (lines 128-134) we have this code:
//instrument js files
require.extensions['.js'] = function(localModule, filename) {
var pattern = blanket.options("filter"),
reporter_options = blanket.options("reporter_options"),
originalFilename = filename,
inputFilename = filename;
filename = blanket.normalizeBackslashes(filename);
Please, kindly change it to:
//instrument js files
require.extensions['.js'] = function(localModule, filename) {
var pattern = blanket.options("filter"),
reporter_options = blanket.options("reporter_options"),
originalFilename = filename,
inputFilename = blanket.normalizeBackslashes(filename);
filename = inputFilename;
Otherwise a exception will explode in the console because of windows path. Blanket Issue 491
- Add Friend endpoints (https://github.com/hcbelias/socialnetwork/tree/release)