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 ├── .pre-commit-config.yaml ├── 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 install
forms the project root to install all the dependencies -
npm run build
transpiles the typescript code to/dist
folder -
npm run start
starts the node server -
npm run test
runs tests located under/dist
folder, prints the jest output under/build
folder and reports test coverage. The report located under/coverage_output
folder is then picked by Sonarqube.
Metadata
The following are typical metadata values that can be used for components based on this quickstarter: Note that the OpenShift resources will be labeled based on this metadata.
name: <the component id (this is the default, if omitted)>
description: "Some microservice implemented in TypeScript over Express"
supplier: https://example.com
version: 1.0.1
type: ods
role: backend
runtime: node
runtimeVersion: 22
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 build
command is executed to build the application and then the build is copied to thedocker/dist
folder. -
Unit Testing :
npm run test
command is executed for running unit tests and to generate coverage report. The results can be seen form the Jenkins console output.
include::partials$secret-scanning-with-gitleaks.adoc
Builder agent used
This quickstarter uses Node.JS 22 builder agent for Jenkins.