CLI (npm create cloudflare)
Cloudflare provides a CLI command for creating new Workers and Pages projects — npm create cloudflare, powered by the create-cloudflare package.
Create a new application
Open a terminal window and run:
$ npm create cloudflare@latest
$ yarn create cloudflare@latest
Running this command will prompt you to install the create-cloudflare package, and then ask you questions about the type of application you wish to create.
Web frameworks
If you choose the “Framework Starter” option, you will be prompted to choose a framework to use. The following frameworks are currently supported:
When you use a framework, npm create cloudflare directly uses the framework’s own command for generating a new projects, which may prompt additional questions. This ensures that the project you create is up-to-date with the latest version of the framework, and you have all the same options when creating you project via npm create cloudflare that you would if you created your project using the framework’s tooling directly.
Deploy
Once your project has been configured, you will be asked if you would like to deploy the project to Cloudflare. This is optional.
If you choose to deploy, you will be asked to sign into your Cloudflare account (if you aren’t already), and your project will be deployed.
Creating a new Pages project that is connected to a git repository
To create a new project using npm create cloudflare, and then connect it to a Git repository on your Github or Gitlab account, take the following steps:
- Run
npm create cloudflare@latest, and choose your desired options - Select
noto the prompt, “Do you want to deploy your application?”. This is important — if you selectyesand deploy your application from your terminal (Direct Upload), then it will not be possible to connect this Pages project to a git repository later on. You will have to create a new Cloudflare Pages project. - Create a new git repository, using the application that
npm create cloudflare@latestjust created for you. - Follow the steps outlined in the Git integration guide
CLI Arguments
C3 collects any required input through a series of interactive prompts. You may also specify your choices via command line arguments, which will skip these prompts. To use C3 in a non-interactive context such as CI, you must specify all required arguments via the command line.
This is the full format of a C3 invocation alongside the possible CLI arguments:
$ npm create cloudflare@latest [--] [<DIRECTORY>] [OPTIONS] [-- <NESTED ARGS...>]
$ yarn create cloudflare@latest [--] [<DIRECTORY>] [OPTIONS] [-- <NESTED ARGS...>]
$ pnpm create cloudflare@latest [--] [<DIRECTORY>] [OPTIONS] [-- <NESTED ARGS...>]
$ bun create cloudflare@latest [--] [<DIRECTORY>] [OPTIONS] [-- <NESTED ARGS...>]
DIRECTORYstring- The directory where the application should be created. The name of the application is taken from the directory name.
NESTED ARGS..string[]- CLI arguments to pass to eventual third party CLIs C3 might invoke (in the case of full-stack applications).
--categorystringThe kind of templates that should be created.
The possible values for this option are:
hello-world: Hello World exampleweb-framework: Framework Starterdemo: Demo applicationremote-template: Template from a GitHub repo
--typestringThe type of application that should be created.
The possible values for this option are:
hello-world: A basic “Hello World” Cloudflare Worker.hello-world-durable-object: A Durable Object and a Worker to communicate with it.common: A Cloudflare Worker which implements a common example of routing/proxying functionalities.scheduled: A scheduled Cloudflare Worker (triggered via Cron Triggers).queues: A Cloudflare Worker which is both a consumer and produced of Queues.openapi: A Worker implementing an OpenAPI REST endpoint.pre-existing: Fetch a Worker initialized from the Cloudflare dashboard.
--frameworkstringThe type of framework to use to create a web application (when using this option,
--typeis ignored).The possible values for this option are:
angularastrodocusaurusgatsbyhononextnuxtqwikreactremixsolidsveltevue
--templatestringCreate a new project via an external template hosted in a git repository
The value for this option may be specified as any of the following:
user/repogit@github.com:user/repohttps://github.com/user/repouser/repo/some-template(subdirectories)user/repo#canary(branches)user/repo#1234abcd(commit hash)bitbucket:user/repo(BitBucket)gitlab:user/repo(GitLab)
See the
degitdocs for more details.At a minimum, templates must contain the following:
package.jsonwrangler.tomlsrc/containing a worker script referenced fromwrangler.toml
See the templates folder of this repo for more examples.
--deployboolean- Deploy your application after it has been created.
--langstringThe programming language of the template.
The possible values for this option are:
tsjspython
--tsboolean- Use TypeScript in your application. Deprecated. Please use
--lang=tsinstead.
- Use TypeScript in your application. Deprecated. Please use
--gitboolean- Initialize a local git repository for your application.
--openboolean- Open with your browser the deployed application (this option is ignored if the application is not deployed).
--existing-scriptstringThe name of an existing Cloudflare Workers script to clone locally. When using this option,
--typeis coerced topre-existing.When
--existing-scriptis specified,deploywill be ignored.
-y,--accept-defaultsboolean- Use all the default C3 options each can also be overridden by specifying it.
--auto-updateboolean- Automatically uses the latest version of C3.
-v,--versionboolean- Show version number.
-h,--helpboolean- Show a help message.