You need to enable JavaScript to run this app.
Volcano Engine Function as a Service

Volcano Engine Function as a Service

Copy page
Download PDF
Native Node.js runtime
Development methods
Copy page
Download PDF
Development methods
For web applications, your program is an HTTP server that runs in the Native Node.js runtime. This topic outlines the specifications and guidelines you need to follow when you develop an HTTP server.​
Service specifications​
When developing an HTTP server locally, follow service specifications. For details, see Service specifications.​
Development example​
In the Native Node.js runtime, veFaaS forwards requests to your HTTP server, and you can directly write the business logic of your function.​
The following is a complete code example of developing an application using the Express framework.​
  • index.js:​
  • ​
    const express = require("express");​
    ​
    const port = process.env._FAAS_RUNTIME_PORT || 8000;​
    ​
    const app = express();​
    ​
    app.get("/v1/ping", (req, res) => {​
    res.send("ok");​
    });​
    ​
    app​
    .listen(port, "0.0.0.0", () => {​
    console.log("start success.");​
    })​
    .on("error", (e) => {​
    console.error(e.code, e.message);​
    });​
    ​
  • run.sh:​
  • ​
    #!/bin/bash​
    set -ex​
    cd `dirname $0`​
    ​
    exec node index.js​
    ​
Request processing​
Since you implement your own HTTP server in the Native Node.js runtime, you can define custom request processing logic in the HTTP server code. The following code demonstrates a simple request handler interface.​
​
# Request processing​
app.get("/", (req, res) => {​
res.send("Hello Express");​
});​
​
Configure a startup command​
After you develop and compile the code, configure the startup command and listening port in the console when you create a serverless application hosting. In this example, the startup command is ./run.sh, and the listening port is 8000.​
Use environment variables​
For Native Node.js functions, you can configure the environment variables required by the runtime of your function in the console and retrieve them in your code to implement function processing logic. veFaaS injects configured environment variables into the container where the function runs, and the program can read them using a built-in library for the programming language. For example, if the key of an environment variable is envKey, you can use the following code sample to read the environment variable.​
​
const envValue = process.env.envKey​
​
Use TypeScript​
  1. When developing a local code package, install the TypeScript package in package.json and add a script file.​
  • ​
    {​
    "name": "package-name",​
    "version": "1.0.0",​
    "description": "",​
    "main": "index.js",​
    "scripts": {​
    "build": "tsc",​
    "start": "node ./dist/index.js"​
    },​
    "author": "",​
    "dependencies": {​
    "typescript": "^4.7.3"​
    }​
    }​
    ​
  1. Add build.sh in addition to run.sh, and execute build.sh after development is complete.​
  • ​
    npm run build​
    ​
  1. Run the following command to package the files into vefaas-native-typescript archive.​
  • ​
    zip -FSr vefaas-native-typescript.zip .​
    ​
  1. Upload the ZIP package via the console and redeploy.​
Last updated: 2026.08.19 14:06:07