Skip to content

Commit 748aab0

Browse files
TC-MOjbartadev
andauthored
docs: rewrite local development section (#931)
rewrite the local development section for clarity & conciseness restructure the document with additional headings add admonitions about: prequisites monetization benefits of local development --------- Co-authored-by: Jan Bárta <[email protected]>
1 parent 917e361 commit 748aab0

File tree

2 files changed

+76
-34
lines changed

2 files changed

+76
-34
lines changed
-540 KB
Loading
Lines changed: 76 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,131 @@
11
---
22
title: Local development
33
sidebar_position: 1
4-
description: Create your first Actor locally on your machine and then deploy it to the Apify platform and run it in the cloud.
4+
description: Create your first Actor locally on your machine, deploy it to the Apify platform, and run it in the cloud.
55
slug: /actors/development/quick-start/locally
66
---
77

8-
**Create your first Actor locally on your machine and then deploy it to the Apify platform and run it in the cloud.**
8+
**Create your first Actor locally on your machine, deploy it to the Apify platform, and run it in the cloud.**
99

1010
---
1111

12-
> Prerequisite - You need to have [Node.js](https://nodejs.org/en/) version 16 or higher with NPM installed on your computer.
12+
:::info Prerequisites
1313

14-
## 1. Install Apify CLI
14+
You need to have [Node.js](https://nodejs.org/en/) version 16 or higher with NPM installed on your computer.
1515

16-
On macOS (or Linux), you can install the Apify CLI via the Homebrew package manager.
16+
:::
17+
18+
## Install Apify CLI
19+
20+
### MacOS/Linux
21+
22+
You can install the Apify CLI via the [Homebrew package manager](https://brew.sh/).
1723

1824
```bash
1925
brew install apify-cli
2026
```
2127

22-
Otherwise, use [NPM](https://www.npmjs.com/) to install the Apify CLI.
28+
### Other platforms
29+
30+
Use [NPM](https://www.npmjs.com/) to install the Apify CLI.
2331

2432
```bash
2533
npm -g install apify-cli
2634
```
2735

28-
For more installation and advanced usage information, see the [Apify CLI documentation](https://docs.apify.com/cli/).
36+
Visit [Apify CLI documentation](https://docs.apify.com/cli/) for more information regarding installation and advanced usage.
2937

30-
## 2. Create your Actor
38+
## Create your Actor
3139

32-
You can use the following command to create an Actor:
40+
To create a new Actor, use the following command:
3341

3442
```bash
3543
apify create
3644
```
3745

38-
You will be prompted to name your Actor (e.g, my-actor), and choose the programming language you would like to use (JavaScript, TypeScript, or Python). Next, you will be presented with a list of Actor development templates. After choosing your preferred template the CLI will:
46+
The CLI will prompt you to:
3947

40-
- Create a `my-actor` directory containing boilerplate code.
41-
- Install all the project dependencies.
48+
1. _Name your Actor_: Enter a descriptive name for your actor, such as `your-actor-name`
49+
1. _Choose a programming language_: Select the language you want to use for your Actor (JavaScript, TypeScript, or Python).
50+
1. _Select a development template_: Choose a template from the list of available options.
51+
52+
After selecting the template, the CLI will:
53+
54+
- Create a `your-actor-name` directory with the boilerplate code.
55+
- Install all project dependencies
4256

4357
![Creation](./images/actor-create.gif)
4458

45-
Finally, switch to your newly created Actor directory:
59+
Navigate to the newly created Actor directory:
4660

4761
```bash
48-
cd my-actor
62+
cd your-actor-name
4963
```
5064

51-
## 3. Explore the source code in your editor
65+
## Explore the source code in your editor
5266

53-
Next, let's explore the Actor's source code. We will use the "PuppeteerCrawler in JavaScript" template code as an example, but all Actor templates follow a similar organizational pattern. The important parts are:
67+
After creating your Actor, explore the source code in your preferred code editor, We'll use the `Crawlee + Puppeteer + Chrome` template code as an example, but all Actor templates follow a similar organizational pattern. The important directories and filer are:
5468

55-
- `src` directory and, namely, the `src/main.js` file, which is the actual code of an Actor.
56-
- `actor` directory containing Actor's definition files such as `actor.json` and `Dockerfile`. These are important once you deploy your code to the Apify platform.
57-
- `storage` directory containing the local emulation of [Apify Storage](../../../storage), namely [key-value store](../../../storage/key-value-store), [dataset](../../../storage/dataset), and [request queue](../../../storage/request-queue).
69+
### `src` Directory
5870

59-
![Actor source code](./images/actor-local-code.png)
71+
- `srx/main.js`: This file contains the actual code of your Actor
6072

61-
> The following chapters will teach you more about an Actor's structure and files.
73+
### `actor` Directory
6274

63-
## 4. Run it locally
75+
- `[actor/json](https://docs.apify.com/platform/actors/development/actor-definition/actor-json)`: This file defines the Actor's configuration, such as input and output specifications.
76+
- `[Dockerfile](https://docs.apify.com/platform/actors/development/actor-definition/dockerfile)`: This file contains instructions for building the Docker image for your Actor.
6477

65-
To run the Actor, call:
78+
### `storage` Directory
79+
80+
- This directory emulates the [Apify Storage](../../../storage/index.md)
81+
- [Dataset](../../../storage/dataset.md)
82+
- [Key-Value Store](../../../storage/key_value_store.md)
83+
- [Request Queue](../../../storage/request_queue.md)
84+
85+
![Actor source code](./images/actor-local-code.png)
86+
87+
## Run it locally
88+
89+
To run your Actor locally, use the following command:
6690

6791
```bash
6892
apify run
6993
```
7094

71-
Shortly after that, you will see the log of the Actor. The results will be stored in the local dataset under the `storage/dataset/default` directory.
95+
After executing this command, you will see the Actor's log output in your terminal. The results of the Actor's execution will be stored in the local dataset located in the `storage/dastasets/default` directory.
7296

7397
![Actor source code](./images/actor-local-run.png)
7498

75-
## 5. Deploy it to Apify platform
99+
:::note Local testing & debugging
76100

77-
In order to push your Actor to the Apify platform, you need to first sign in to Apify with the CLI tool:
101+
Running the Actor locally allows you to test and debug your code before deploying it to the Apify platform.
78102

79-
```bash
80-
apify login
81-
```
103+
:::
82104

83-
And then, you can push your Actor under your Apify account with the following:
105+
## Deploy it to Apify platform
84106

85-
```bash
86-
apify push
87-
```
107+
Once you are satisfied with your Actor, to deploy it to the Apify platform, follow these steps:
108+
109+
1. _Sign in to Apify with the CLI tool_
110+
111+
```bash
112+
apify login
113+
```
114+
115+
This command will prompt you to provide your API token that you can find in Console.
116+
117+
1. _Push your Actor to the Apify platform_
118+
119+
```bash
120+
apify push
121+
```
122+
123+
This command will upload your Actor's code and configuration to the Apify platform, where it can be executed and managed.
124+
125+
:::note Actor monetization
126+
127+
If you have successfully completed your first Actor, you may consider [sharing it with other users and monetizing it](../../publishing/index.mdx). The Apify platform provides opportunities to publish and monetize your Actors, allowing you to share your work with the community and potentially generate revenue.
128+
129+
:::
88130
89-
> If you successfully finished your first Actor, you may consider [sharing it with other users and monetizing it](../../publishing/index.mdx).
131+
By following these steps, you can seamlessly deploy your Actors to the Apify platform, enabling you to leverage its scalability, reliability, and advanced features for your web scraping and data processing projects.

0 commit comments

Comments
 (0)