{
  "schema_version": 2,
  "id": "operate/oss_and_stack/stack-with-enterprise/deprecated-features/triggers-and-functions/Development",
  "title": "Development",
  "url": "https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/triggers-and-functions/development/",
  "summary": "How to develop for triggers and functions",
  "aliases": [
    "/develop/interact/programmability/triggers-and-functions/development/"
  ],
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-21T16:36:38+01:00",
  "page_type": "content",
  "content_hash": "e17d4e2ceb0ffe5b293d53d4b4e7aea4aecb733e8e37f4a28e458dcda94144ae",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "To aid in the development of new libraries of triggers and functions, you can use the type declaration files for the [triggers and functions API](https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/triggers-and-functions/concepts/JavaScript_API), which allows your preferred development environment to provide autocompletion and type checking. You can install this information using the following command:\n\n[code example]\n\nOr you can manually add it as a devDependency to your `package.json` file:\n\n[code example]"
    },
    {
      "id": "example-project-setup",
      "title": "Example project setup",
      "role": "example",
      "text": "Create an empty directory for your new triggers and functions project, `my_first_project`. Navigate to the folder and run the following command:\n\n[code example]\n\nUpdate the `package.json` to add the gears API to the `devDependencies` object.\n\n[code example]\n\nInstall the dependencies using `npm install`.\n\nCreate a new file, `index.js` and import the gears-api module. While this step is not strictly necessary, doing so will enable code intelligent code completion when adding the `registerFunction`:\n\n[code example]\n\nTo automate the deployment, update the `scripts` section in `package.json`:\n\n[code example]\n\nNow you can deploy your code to Redis Stack using the following command:\n\n[code example]\n\nThe provided URL should follow the following format:\n\n`<redis[s]://[[username][:password]@][host][:port][/db-number]>`\n\nYou can now run your Redis Stack function:\n\n[code example]"
    },
    {
      "id": "example-function-using-a-third-party-npm-package",
      "title": "Example function using a third-party `npm` package",
      "role": "example",
      "text": "If you want to use a third-party `npm` package in your Redis Stack function, the overall process is nearly the same as already discussed, with just a couple of differences.\n\nFirst, you'll need to install your package using `npm install`. For this example, the `pi` symbol from the `math.js` library will be used in a simple function that calculates the area of a circle.\n\n[code example]\n\nNote: your `package.json` file will also be updated with the new dependency. For example:\n\n[code example]\n\nNext, you'll import the required symbol(s) into your function.\n\n[code example]\n\nLoad and run your new function as described in the previous section."
    }
  ],
  "examples": [
    {
      "id": "overview-ex0",
      "language": "bash",
      "code": "npm install https://gitpkg.now.sh/RedisGears/RedisGears/js_api --save-dev",
      "section_id": "overview"
    },
    {
      "id": "overview-ex1",
      "language": "json",
      "code": "\"devDependencies\": {\n  \"@redis/gears-api\": \"https://gitpkg.now.sh/RedisGears/RedisGears/js_api\"\n}",
      "section_id": "overview"
    },
    {
      "id": "example-project-setup-ex0",
      "language": "bash",
      "code": "$ npm init -y -f\nnpm WARN using --force Recommended protections disabled.\nWrote to /home/work/my_first_project/package.json:\n\n{\n  \"name\": \"my_first_project\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"keywords\": [],\n  \"author\": \"\",\n  \"license\": \"ISC\"\n}",
      "section_id": "example-project-setup"
    },
    {
      "id": "example-project-setup-ex1",
      "language": "js",
      "code": "{\n  \"name\": \"my_first_project\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"devDependencies\": {\n    \"@redis/gears-api\": \"https://gitpkg.now.sh/RedisGears/RedisGears/js_api\"\n  },\n  \"keywords\": [],\n  \"author\": \"\",\n  \"license\": \"ISC\"\n}",
      "section_id": "example-project-setup"
    },
    {
      "id": "example-project-setup-ex2",
      "language": "JavaScript",
      "code": "#!js name=lib api_version=1.0\n\nimport { redis } from '@redis/gears-api';\n\nredis.registerFunction(\"test\", ()=>{\n    return \"test\";\n});",
      "section_id": "example-project-setup"
    },
    {
      "id": "example-project-setup-ex3",
      "language": "json",
      "code": "\"scripts\": {\n  \"deploy\": \"gears-api index.js\"\n}",
      "section_id": "example-project-setup"
    },
    {
      "id": "example-project-setup-ex4",
      "language": "bash",
      "code": "> npm run deploy -- -r redis://localhost:6379\n\n> deploy\n> gears-api index.js\n\nDeployed! :)",
      "section_id": "example-project-setup"
    },
    {
      "id": "example-project-setup-ex5",
      "language": "bash",
      "code": "127.0.0.1:6379> TFCALL lib.test 0\n\"test\"",
      "section_id": "example-project-setup"
    },
    {
      "id": "example-function-using-a-third-party-npm-package-ex0",
      "language": "bash",
      "code": "npm install mathjs",
      "section_id": "example-function-using-a-third-party-npm-package"
    },
    {
      "id": "example-function-using-a-third-party-npm-package-ex1",
      "language": "json",
      "code": "\"dependencies\": {\n    \"mathjs\": \"^12.0.0\"\n}",
      "section_id": "example-function-using-a-third-party-npm-package"
    },
    {
      "id": "example-function-using-a-third-party-npm-package-ex2",
      "language": "javascript",
      "code": "#!js api_version=1.0 name=lib\n\nimport { redis } from '@redis/gears-api';\nimport { pi } from 'mathjs';\n\nfunction calculateCircleArea(client, radius) {\n  return pi * radius * radius;\n}\n\nredis.registerFunction('calculateArea', calculateCircleArea);",
      "section_id": "example-function-using-a-third-party-npm-package"
    }
  ]
}
