Node.JS

Kato 5.1 version already supports source deployment of NodeJS front-end projects. You can publish Vue, React, Angular and other projects directly on Kato.

View the document: Deploy the NodeJS front-end project to Kato

NodeJS Language Identification Specification

By default, the platform will recognize it as a NodeJS project based on whether there is package.json in the source root directory.

Platform Compilation and Operation Mechanism

  1. The pre-compilation process will detect whether the startup command configuration file Procfile is defined, and if it is not defined, it will read the value of script.start in the package.json file to generate the startup configuration file ;
  2. After the pre-compilation process is completed, the nodejs buildpack will be selected according to the language type to compile the project. During the compilation process, the defined Node version and Nodejs related dependencies will be installed;
  3. After the compilation is completed, it will be checked whether the Procfile parameter is set on the platform, and if it is configured, the startup command configuration file Procfile will be overwritten.

NodeJS Project Source Code Specification

In this step, you need to provide a usable NodeJS source code program for deployment on the Kato platform. This application must at least meet the following conditions:

  1. A NodeJS project that can run normally locally
  2. The source code program must be hosted on related git or svn services such as gitlab
  3. package.json must exist in the root path of the source code program, which is used to manage the dependencies of the NodeJS project and is also a necessary condition for Kato to recognize the NodeJS language
Procfile Specification

If the project does not define a Procfile file, the platform will generate a default Procfile based on the value of script.start in the package.json file.

web: npm start

The above is the default Procfile, if you need to expand more startup parameters, you can customize the Procfile.

  1. There is a space between web: and npm
  2. The end of the file cannot contain special characters

Compile and Run Environment Settings

Node Version Support

Currently Kato supports the following versions of Node:

4.9.1 
5.12.0 
6.14.4 
7.10.1 
8.12.0 
9.11.2
10.13.0 
11.1.0 

The default version of the platform uses 8.12.0. You can use engines to specify the version in package.json:

{
      "name": "myapp",
      "description": "a really cool app",
      "version": "0.0.1",
      "engines": {
        "node": "4.8.7"
      }
}

Versions after 0.8.5 including 0.11.13 are also supported. The following is an example of using the 0.11.x version:

{
  "engines": {
    "node": "0.11.x"
  }
}

The npm version is not necessary and can be omitted, because npm is bound to node.

Dependent Package Installation

The Node project supports the use of npm package manager and yarn package manager to install dependent packages. If the yarn.lock file exists, Use yarn (version 1.9.4 is supported by default) to install dependencies and run scripts, otherwise use npm.

Yarn definition method

{
  "engines": {
    "yarn": "1.9.4"
  }
}
Custom Build Script

If your application needs to perform additional operations when building, you can add postinstall under the scripts node of package.json Script, this script will be executed automatically after buildpack finishes executing npm install —production, please refer to package.json example:

{
  "name": "node-hello",
  "version": "0.0.1",
  "description": "nodejs demo",
  "dependencies": {
    "bower": "~1.3.9",
    "grunt-cli": "~0.1.13",
  },
  "scripts": {
    "start": "node index.js",
    "test": "mocha",
    "postinstall": "bower install && grunt build"
  },
  "engines": {
    "node": "9.3.0"
  }
}

The system does not come with grunt, gulp, bower by default, but it will install the dependencies under the dependencies and devDependencies nodes in package.json, so custom execution commands need to be added as dependencies to this node. Otherwise, commands may not be found, and so are the dependencies that these tools need to execute.

Repository Private Server Settings

npm Private Server Settings

npm build uses Taobao private server address by default: https://registry.npm.taobao.org

If you want to be able to customize the private server repository address used during npm install, you need to add custom environment variables:

BUILD_NPM_REGISTRY=http://XXXX:8080/repository/npm-group/
Yarn Private Server Settings

Yarn build does not support environment variable setting private server, but the private server address can be set through the preinstall keyword.

"scripts": {
	"preinstall": "bash preinstall.sh",
	"build": "/tmp/build/node_modules/.bin/vue-cli-service build --mode test"
},

In the above package.json file, the keyword preinstall specifies what to do before installing the dependency (yarn install). The example is a script file in the root directory of the execution code, and its content is to set up a private server:

#!/bin/bash
yarn config set registry http://XXXX:8080/repository/npm-group/ --global

Sample Demo Program

Example https://github.com/gridworkz/nodejs-demo