If you are using Windows, I would rather you installed the following packages globally on your local computer due to the build processes are heavily relaying on them:
- Rimraf:
npm install -g rimraf - Typescript 2.0 compiler:
npm install -g typescript - Mocha:
npm install -g mocha - Istanbul:
npm install -g istanbul
Features
- Built in NodeJS using ExpressJS
- Models are validated by Joi
- Used YARN package manager
- Deployment with Docker
- Written in TypeScript 2.0
- Static code analysis using TsLint
- Unit tests for middlewares and models are built using Mocha, Sinon and Chai
- Integration tests for API endpoints with supertest
- Istanbul for code coverage measurements
Installation
- Clone this repository
- Step into the 'backend' directory
- Install yarn package manager globally
npm install -g yarn - Make sure you are in the 'backend' directory where the package.json locates. Install all the backend dependencies:
yarn install(or alternatively you can use npm as well, but I provided lock files only for yarn) - Build the application
npm run build - Start it!
npm run start
Configuration The backend comes with a default built-in configuration which can be easily overridden by copying 'src/config.json.dist' into the dist/ folder. Don't forget to rename it to 'config.json'. After that, when the backend starts up again it will use the configuration from config.json. By default the backend uses tcp:3000 port and allows cross domain request only from localhost:8080.
Using Docker for deployment
First create a build (by running npm run build), then just hit npm run docker-build to create the docker image.
When it's done you can easily start the container with the following command: docker run -p 3000:3000 bkotyik/fullstack-backend
Note that in this case the port number 3000 of the container will be forwarded to the same port of your machine.
So the service will be available at http://localhost:3000
Running the tests
Tests can be run by executing npm run test. The command will run both unit and integration tests.
If you want to check the code coverage just hit npm run coverage
API Endpoints The application exposes three endpoints:
- POST /users: Accepts a JSON formatted document which will be handled as a user model. If valid, a success message will be sent back to the client. Else the validation errors will be shown in the response.
- GET /users/metadata: Publishes the metadata of the User model so that the frontend will be able to use the validation rules of the backend.
- GET /occupations: Gives a list of pre-defined occupations.
Design decisions
- For the sake of simplicity, every middleware can terminate the pipeline. Basically its not a good practice, because it makes the control flow unpredictable. But because this demo has only 3 middlewares and one of the is the error handler middleware, I deciced to keep my implementation simple and give the ability for those two middlewares to handle the output instead of delegating this task for a dedicated middleware.
Features
- Built with Angular 2.1 and ng-bootstrap which relies on Bootstrap 4
- Bundled using Webpack 2
- Unit tested using Jasmine and E2E tested using Protractor
- Uses validation metadata exposed by backend
- Production build using Angular 2 AOT
Installation
- Clone this repository
- Step into the 'frontend' directory
- Install yarn package manager globally
npm install -g yarn - Make sure you are in the 'frontend' directory where the package.json is located.
Install all the backend dependencies:
yarn install(or alternatively you can use npm as well, but I provided lock files only for yarn) - Build the frontend by setting NODE_ENV=build and then create a docker container from the output
npm run buildcreates a build into the 'dist' directory andnpm run docker-buildmakes a container from that. - Or alternatively start it in development mode by running
npm run start
Configuration The frontend comes with a default built-in configuration which can be easily overridden by editing the config.js file under the dist/ folder. By default the frontend will be served via the tcp:8080 port and expects the backend to be available at the http://localhost:3000 address.
Using Docker for deployment
First create a build, then just hit npm run docker-build to create the docker image.
When it's done you can easily start the container with the following command: docker run -p 8080:8080 bkotyik/fullstack-frontend
Not that in this case the port 8080 of the container will be forwarded to your machine.
So the frontend will be available at http://localhost:8080
Running the tests
Tests can be run by executing npm run test. The command will run only unit tests.
In order to be able to run E2E, first update your chrome webdriver by executing the following line in a command prompt: npm run webdriver-update
After that start an instance from both the frontend and the backend, and execute npm run e2e from the command line.