tencent cloud

피드백

Examples

마지막 업데이트 시간:2023-06-05 15:06:13

    These examples provide code snippets based on Node.js 12.16 for your reference.

    You can click scf-nodejs-code-snippet to obtain the relevant code snippets and directly use them for deployment.

    Obtaining Environment Variables

    This example shows you how to obtain all or a single environment variable.

    'use strict';
    exports.main_handler = async (event, context) => {
            console.log(process.env)
        console.log(process.env.SCF_RUNTIME)
        return "Hello world"
    };
    

    Formatting Local Time

    This example uses the moment library to obtain the local time, and provides a time formatted output method to output date and time in the specified format.

    The SCF environment uses the UTC format by default. To output in Beijing time, you can add the TZ=Asia/Shanghai environment variable to the function.

    'use strict';
    const moment = require('moment')
    exports.main_handler = async (event, context) => {
        let currentTime = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss')
        console.log(currentTime)
        return "hello world"
    };
    

    Initiating Network Connection in Function

    This example shows you how to use the requests library to initiate network connections in a function and obtain page information. You can run the npm install request command under the project directory to install this dependent library.

    'use strict';
    var request = require('request');
    exports.main_handler = async (event, context) => {
        request('https://cloud.tencent.com/', function (error, response, body) {
            if (!error && response.statusCode == 200) {
                console.log(body) // Processing logic for successful request
            }
        })
        return "success"
    };
    
    문의하기

    고객의 업무에 전용 서비스를 제공해드립니다.

    기술 지원

    더 많은 도움이 필요하시면, 티켓을 통해 연락 바랍니다. 티켓 서비스는 연중무휴 24시간 제공됩니다.

    연중무휴 24시간 전화 지원