Git Product home page Git Product logo

workshop-nodejs-ci-cd's Introduction

Workshop with NodeJS

List of packages

  • express
  • jest
  • jest-junit
  • supertest

1. Start node server

$npm install
$npm start

Access to api http://localhost:3000

2. API Testing with Jest

$npm test

3. Deploy to target server with PM2

$pm2 start src/index.js
$pm2 restart all

4. API testing with Postman and Newman command

$cd postman
$newman run node-api.postman_collection.json

// Report
$newman run day01.postman_collection.json -r cli,junit

5. Pipeline script

pipeline {
    agent any

    stages {
        stage('demo01') {
            steps {
                git branch: 'main', url: 'https://github.com/up1/workshop-nodejs-ci-cd.git'
                sh '''npm install
npm test'''
            }
        }
        stage('deploy') {
            steps {
                sh 'pm2 restart all'
            }
        }
        stage('api-test') {
            steps {
                sh '''cd postman
newman run day01.postman_collection.json -r cli,junit'''
            }
        }
    }
}

6. SonarQube and Sonar Scanner

Config file sonar-project.properties

sonar.projectKey=node-example
sonar.projectName=node-example
sonar.projectVersion=1.0

sonar.sources=src
sonar.tests=__tests__
sonar.sourceEncoding=UTF-8
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.testExecutionReportPaths=coverage/test-reporter.xml

Edit file <install_directory>/conf/sonar-scanner.properties

sonar.host.url=http://139.59.226.126:9000
sonar.login=admin
sonar.password=xitgmLwmp

Start

$<install_directory>/bin/sonar-scanner

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.