Cloudflare Workers don’t actually require any installation to run. However, You will need to set your Global API key from Cloudflare as an environmental variable named CLOUDFLARE_AUTH_KEY, and your Cloudflare account email as an environmental variable named CLOUDFLARE_AUTH_EMAIL. You can get your Global API key from your Cloudflare profile page.
Environmental variables are variables that live inside your terminal.
For Mac and Linux users, you can set environmental variables like this:
export CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE
export CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAILAnd for Windows (CMD) users, you can set environmental variables like this:
set CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE
set CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAILYou’ll need to redefine your environmental variables after each time you close your terminal.
Next, install the Serverless Framework via npm which was already installed when you installed Node.js.
Open up a terminal and type npm install -g serverless to install Serverless.
npm install -g serverlessOnce the installation process is done you can verify that Serverless is installed successfully by running the following command in your terminal:
serverlessTo see which version of serverless you have installed run:
serverless --versionRemember, you need at least version 1.31.0 to use Cloudflare Workers with Serverless.
Finally, add our serverless-cloudflare-workers plugin to your project by running npm install --save serverless-cloudflare-workers.