Node.JS

: 5.1 version already supports the deployment NodeJS front

end projects from source code, you can directly publish Vue, React, Angular and other projects in

NodeJS Language Recognition Specification

By default, the platform will identify a NodeJS project according to whether there ispackage.jsonin the source root directory.

Platform compile and run mechanism

  1. The pre-compilation process will detect whether the startup command configuration fileProcfileis defined, if not, it will read thescript.startvalue in thepackage.jsonfile 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 check whether the Procfile parameter is set on the platform. If it is configured, the startup command configuration file Procfile will be rewritten.

NodeJS project source code specification

In this step, you need to provide an available NodeJS source program for deployment on the Rainbond platform. This application must at least meet the following conditions:

  1. Locally working NodeJS project
  2. The source code program must be hosted on a related git or svn service such as gitlab
  3. There must bepackage.jsonin 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 Rainbond to recognize it as the NodeJS language
Procfile specification

If the project does not define a Procfile file, the platform will generate a default the package.json file.

  1. web: npm start

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

  1. web: there is a space betweenandnpm
  2. End of file cannot contain special characters

Compile and run environment settings

Node version support

Currently Rainbond supports Node. The following version is:

  1. 4.9.1
  2. 5.12.0
  3. 6.14.4
  4. 7.10.1
  5. 8.12.0
  6. 9.11.2
  7. 10.13.0
  8. 11.1.0

The platform default version uses8.12.0.Version:can be specified using engines in package.json

  1. {
  2. "name": "myapp",
  3. "description": "a really cool app",
  4. "version": "0.0.1",
  5. "engines": {
  6. "node": "4.8.7"
  7. }
  8. }

Versions after 0.8.5 including 0.11.13 are also supported, the following is an example using version:

  1. {
  2. "engines": {
  3. "node": "0.11.x"
  4. }
  5. }

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

Dependency package installation

The Node project supports using npm package manager and yarn package manager to install dependencies. If there areyarn.lock files, use yarn (default support version 1.9.4) to install dependencies and run scripts, otherwise use npm.

  • How yarn is defined
  1. {
  2. "engines": {
  3. "yarn": "1.9.4"
  4. }
  5. }
custom build script

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

  1. {
  2. "name": "node-hello",
  3. "version": "0.0.1",
  4. "description": "nodejs demo",
  5. "dependencies" : {
  6. "bower": "~1.3.9" ,
  7. "grunt-cli": "~0.1.13",
  8. },
  9. "scripts": {
  10. "start": "node index.js",
  11. "test": "mocha",
  12. "postinstall": "bower install && grunt build"
  13. },
  14. "engines": {
  15. "node": "9.3.0"
  16. }
  17. }

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

Warehouse private server settings
npm private server settings

By default, npm builds use Taobao private server address: https://registry.npm.taobao.org If you want to be able to customize the private server warehouse address used in npm install , you need to add custom environment variables:

  1. BUILD_NPM_REGISTRY=http://XXXX:8080/repository/npm-group/
yarn private server settings

The yarn build does not support setting the private server by environment variables, but you can set the private server address through the preinstall keyword.

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

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

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

Sample demo program

Examplehttps://github.com/goodrain/nodejs-demo