Backend Node (be-node-express)
What files / architecture is generated?
The package json is generated by simply using npm init -y, while the tsconfig is generated using tsc --init --skipLibCheck --outDir "./dist". The dependencies mentioned below are added to plain package.json file. On top of that, test, build and start script commands are customized to get your node/express application up and running with typescript.
├── Jenkinsfile - Contains Jenkins build configuration ├── LICENSE ├── README.md ├── docker - Contains Dockerfile for the build │ └── Dockerfile ├── package-lock.json - Commit this file as well when you update your dependencies ├── package.json - This file contains all the npm dependencies and build commands for the project. ├── metadata.yml - Component metadata ├── release-manager.yml - Configuration file for the Release Manager ├── sonar-project.properties - SonarQube Configuration ├── src │ ├── sum.ts - Sample function │ ├── index.ts - Entrypoint, This runs first ├── __test__ │ ├── sum.spec.ts - Sample test ├── tsconfig.json - TypeScript Configuration file └── tslint.json - TypeScript Linter Configuration
Node version
When you push your code, your runtime and test code will be compiled using node v10. After deployment the compiled code also runs in node v10. If you developed your code and tests using a different node version locally, this might cause some problems.
This is why we made the tsconfig.json file to be compatible with node v10. So bear in mind that any changes to compiler options might result in compilation and runtime errors. Here are our related changes to tsconfig.json file below:
"compilerOptions": {
"lib": ["es2018"],
"module": "commonjs",
"target": "es2018"
}
Usage - how do you start after you provisioned this quickstarter
-
npm installforms the project root to install all the dependencies -
npm run buildtranspiles the typescript code to/distfolder -
npm run startstarts the node server -
npm run testruns tests located under/distfolder, prints the jest output under/buildfolder and reports test coverage. The report located under/coverage_outputfolder is then picked by Sonarqube.
How this quickstarter is built through jenkins
The build pipeline is defined in the Jenkinsfile in the project root. The mains stages of the pipeline are,
-
Build :
npm run buildcommand is executed to build the application and then the build is copied to thedocker/distfolder. -
Unit Testing :
npm run testcommand is executed for running unit tests and to generate coverage report. The results can be seen form the Jenkins console output.
Builder agent used
This quickstarter uses Nodejs10-Angular builder agent Jenkins builder agent.