Project: Beam (App Definition and Development / Streaming & Messaging)
File: typescript.md

title: "Beam Quickstart for Typescript" aliases: /get-started/quickstart/ /use/quickstart/ /getting-started/ <!-- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> This quickstart shows you how to run an written with the , using the . The Direct Runner executes pipelines locally on your machine. If you're interested in contributing to the Apache Beam Typescript codebase, see the . On this page: {{< toc >}} Make sure you have a development environment installed. If you don't, you can download and install it from the . Due to its extensive use of cross-language transforms, it is recommended that Python 3 and Java be available on the system as well. Clone or download the GitHub repository and change into the `beam-starter-typescript` directory. {{< highlight >}} git clone https://github.com/apache/beam-starter-typescript.git cd beam-starter-typescript {{< /highlight >}} Run the following command to install the project's dependencies. {{< highlight >}} npm install {{< /highlight >}} The pipeline is then built with {{< highlight >}} npm run build {{< /highlight >}} Run the following command: {{< highlight >}} node dist/src/main.js --input_text="Greetings" {{< /highlight >}} The output is similar to the following: {{< highlight >}} Hello World! Greetings {{< /highlight >}} The lines might appear in a different order. The main code file for this quickstart is app.ts (). The code performs the following steps: Define a Beam pipeline that. Creates an initial `PCollection`. Applies a transform (map) to the `PCollection`. Run the pipeline, using the Direct Runner. A `Pipeline` is simply a callable that takes a single `root`

The `Pipeline` function builds up the graph of transformations to be executed. The `PCollection` abstraction represents a potentially distributed, multi-element data set. A Beam pipeline needs a source of data to populate an initial `PCollection`. The source can be bounded (with a known, fixed size) or unbounded (with unlimited size). This example uses the method to create a `PCollection` from an in-memory array of strings. The resulting `PCollection` contains the strings "Hello", "World!", and a user-provided input string. ```typescript root.apply(beam.create(["Hello", "World!", input_text])) ``` Transforms can change, filter, group, analyze, or otherwise process the elements in a `PCollection`. This example uses the transform, which maps the elements of a collection into a new collection: ```typescript .map(printAndReturn); ``` For convenience, `PColletion` has a `map` method, but more generally transforms are applied with `.apply(someTransform())`. To run the pipeline, a runner is created (possibly with some options) ```typescript createRunner(options) ``` and then its `run` method is invoked on the pipeline callable created above. ```typescript .run(createPipeline(...)); ``` A Beam runs a Beam pipeline on a specific platform. If you don't specify a runner, the Direct Runner is the default. The Direct Runner runs the pipeline locally on your machine. It is meant for testing and development, rather than being optimized for efficiency. For more information, see . For production workloads, you typically use a distributed runner that runs the pipeline on a big data processing system such as Apache Flink, Apache Spark, or Google Cloud Dataflow. These systems support massively parallel processing. Different runners can be requested via the runner property on options, e.g. `createRunner({runner: "dataflow"})` or `createRunner({runner: "flink"})`. In this example this value can be passed in via the command line as `--runner=...`, e.g. to run on Dataflow one would write ```sh node dist/src/main.js \ --runner=dataflow \ --project=${PROJECT_ID} \ --tempLocation=gs://${GCS_BUCKET}/wordcount-js/temp --region=${REGION} ``` Learn more about the and look through the . Take a self-paced tour through our . Dive in to some of our favorite . Join the Beam mailing list. Please don't hesitate to if you encounter any issues!