All Products
Document Center

Use fun init to initialize projects

Last Updated: Mar 27, 2020

fun init is a subcommand of Fun. fun init allows you to create Function Compute applications based on templates to simplify Function Compute usage and development. Function Compute provides several commonly used templates. You can also build your own custom templates.


  1. $ fun init --help
  2. Usage: init [options] [location]
  3. Initializes a new fun project
  4. Options:
  5. -o, --output-dir [outputDir] where to output the initialized app into (default: .)
  6. -n, --name [name] name of your project to be generated as a folder (default: fun-app)
  7. --no-input [noInput] disable prompting and accept default values defined template config
  8. -V, --var [vars] template variable
  9. -h, --help output usage information
  10. Examples:
  11. $ fun init
  12. $ fun init helloworld-nodejs8
  13. $ fun init foo/bar
  14. $ fun init gh:foo/bar
  15. $ fun init gl:foo/bar
  16. $ fun init bb:foo/bar
  17. $ fun init github:foo/bar
  18. $ fun init gitlab:foo/bar
  19. $ fun init bitbucket:foo/bar
  20. $ fun init git+ssh://
  21. $ fun init hg+ssh://
  22. $ fun init
  23. $ fun init
  24. $ fun init /path/foo/bar
  25. $ fun init -n fun-app -V foo=bar /path/foo/bar

Option description

Option Default value Description
-o, —output-dir . Optional. Specifies the directory where the initialized application will be stored.
-n, —name fun-app Optional. Specifies the name of your project to be generated as a folder.
—no-input false Optional. Disables prompts and accepts default values for template variables.
-V, —var empty Optional. Specifies a template variable value.
-h, —help null Optional. Displays the usage information of fun init.


  1. The -o,--output-dir option specifies the directory where the initialized application will be stored. By default, the application will be stored in the directory where fun init is running.

    1. $fun init -o /path/foo/bar
  2. The -n,--name option specifies the name of your project to be generated as a folder. Default value: fun-app.

    1. $fun init -n xxx
  3. The -V,--var option allows you to specify values for template variables. A template contains multiple template variables. Most variables have configured default values, but some variables require you to specify a value when the template is being initialized. You can enter a value or press Enter to use the default value. You can also use the -V,--var option to specify variable values. You do not need to specify the values again after you have used this option to specify them. You must enter a key-value pair for this option. The key can contain letters, digits, and underscores (_). The value can contain all characters. Separate a key and a value with an equal sign (=).

    1. $fun init -V foo=bar -V bar=baz
  4. The --no-input option is used to disable prompts and accept default values for template variables. If you do not want to receive the input prompts of template variables, you can use this option to disable prompts and use default values for variables.

    1. $fun init --no-input

Template location

Function Compute provides the following templates:

  • Official templates, including offline and online templates:
    • Offline templates are integrated in Fun.
    • Online templates require you to specify the name of a template. Fun will convert the name to the GitHub address of the template.
  • Git or Mercurial repository templates. The supported abbreviation method is described in the following section.
  • Templates stored in the local file system.

To use a custom template, you can submit your custom template to GitHub, and then run fun init to specify the GitHub address of the template.


  1. To use an official template, you can use the fun init command and select a template as prompted. You do not need to enter the full name of a template to perform a search. If you are not sure which kind of template you need, the fun init command without options provides official templates for you to select as prompted.

    1. $fun init
    2. ? Select a tempalte to init (Use arrow keys or type to search)
    3. helloworld-nodejs8
    4. helloworld-nodejs6
    5. helloworld-python3
    6. helloworld-python2.7
    7. helloworld-java8
    8. helloworld-php7.2
  2. The official template helloworld-nodejs8 is integrated in Fun and can be used offline. This template generates a Node.js 8 Function Compute application that displays the phrase “Hello World”. Many commonly used templates are listed as official templates. You can use a template by specifying the name rather than the entire template repository address.

    1. $fun init helloworld-nodejs8
  3. Git or Mercurial repository templates support multiple prefix abbreviation methods. Addresses of repository templates in GitHub can be written in the user/repo format.

    1. $ fun init foo/bar
    2. $ fun init gh:foo/bar
    3. $ fun init gl:foo/bar
    4. $ fun init bb:foo/bar
    5. $ fun init github:foo/bar
    6. $ fun init gitlab:foo/bar
    7. $ fun init bitbucket:foo/bar
    8. $ fun init git+ssh://
    9. $ fun init hg+ssh://
    10. $ fun init
    11. $ fun init

    Note: You must install the corresponding version control tool.

  4. To use a template stored in the local file system, you can clone an online template to the local file system and specify the template path to initialize the template offline.

  1. $ fun init /path/foo/bar


fun init simplifies your Function Compute usage and development. You can also upload and share your customized Function Compute templates.