First, make sure you have Node.js version 10 or higher installed on your computer by running the following command in the terminal:

node --version

If this command fails or prints a lower version than 10, please follow official Node.js installation instructions for your operating system.

Second, install the Apify command line (CLI) client by running:

npm -g install apify-cli

You can check that the CLI was installed by running:

apify help

This calls the apify help command, which should output all available commands.

$ apify help
Apify command line client to help you create, develop, build and run actors.

  apify-cli/0.6.1 darwin-x64 node-v12.9.4

  $ apify [COMMAND]

  call    Runs the actor remotely on the Apify platform.
  create  Creates a new actor project directory from a selected template.
  info    Displays information about Apify current settings.
  init    Initializes an actor project in an existing directory.
  login   Logs in to the Apify platform using the API token.
  logout  Logs out of the Apify platform.
  push    Uploads the actor to the Apify platform and builds it there.
  run     Runs the actor locally in the current directory.

NOTE: You can also call help for each command,
e.g. apify help create.

That's all you need to create and push your actors from the command line. Let's see next how to use how to use specific commands and how useful they are.

apify create

The fun starts with command apify create as with that command you can start building your actor. You can start writing actor code just after the command finishes because the tool takes care of all other stuff for local actor development.
The command has one mandatory argument name for creating the actor - you can call it, for example:

$ apify create my-new-actor
? Which actor do you want to create? (Use arrow keys)

Project: Empty - Standard and up to date project template with very little boilerplate code.
Project: CheerioCrawler - Standard and up to date template for developing with CheerioCrawler.
Project: PuppeteerCrawler - Standard and up to date template for developing with PuppeteerCrawler.
Example: Hello world - The smallest actor you will see today, it only takes input and generates output.
Example: BasicCrawler - Crawl a list of URLs using raw HTTP requests.
Example: Puppeteer single page - Load a single web page using Chrome and Puppeteer and extract data from it.

Let's choose a "Hello world" actor in this example, which means that the command creates a new folder named my-new-actor with a folder structure ready for developing actors using some of npm package.
The basic structure of an actor looks like this:

├── .gitignore
├── Dockerfile
├── apify.json
├── apify_local
├── main.js
├── node_modules
├── package-lock.json
└── package.json

apify run

This command runs your actor in the current directory. It takes all environment variables that you need for a local run and invokes your actor from the main.js file. It makes sure that all available Apify storages are mocked up locally in the apify_local folder.
You can run my-new-actor, but first you need to change the current directory and then call the run command:

$ cd my-new-actor
$ apify run

Run: node main.js

My test input: Hello world!


apify login

This command uses your API token and authorizes you with your account. You only have to sign in once because the tool stores your credentials under the ~/.apify folder.
To sign up, you need an API token, which you can find on your Apify account page.

When you have your API token ready you can call login, which prompts you for it.

$ apify login

Enter your Apify API token. You can find it at

? token: [hidden]

Success: Logged into Apify!

apify push

If you are successfully logged in to Apify, you can move on to the last step and push the actor to Apify. The command push doesn't have any mandatory options or arguments. You can just call it and all your files from the actor directory upload to Apify and builds the actor. Under the hood, this command packages all files from your actor directory to one zip file. The zip file uploads to the Apify key-value store. The code is there expanded into a multifile editor. The command then builds the actor and prints build logs to your console. The output of the command should look as follows:

$ apify push

Info: Deploying actor 'my-actor' to Apify.
Run: Zipping actor files
Run: Creating actor
{ id: 'kZH6kpyWu8abRsoFF',
  userId: 'RWtczwPasdduTMak',
  name: 'my-new-actor',
  username: 'drobnikj',
  restartOnError: false,
  useSpareCpu: false,
  isPublic: false,
  isAnonymouslyRunnable: false,
  createdAt: '2018-04-10T14:58:10.753Z',
  modifiedAt: '2018-04-10T14:58:10.753Z',
  stats: { totalBuilds: 0, totalRuns: 0, totalUsers: 1 },
   [ { versionNumber: '0.1',
       buildTag: 'latest',
       envVars: [],
       sourceType: 'TARBALL',
       tarballUrl: '' } ],
  defaultRunOptions: { build: 'latest', timeoutSecs: 3600, memoryMbytes: 512 },
   { body: '{ "hello": 123 }',
     contentType: 'application/json; charset=utf-8' } }
Run: Building actor
{ id: 'ifLN2nscNMcdmTjMi',
  actId: 'kZH6kpyWu8abRsoFF',
  userId: 'RWtczwPasdduTMak',
  startedAt: '2018-04-10T14:58:11.156Z',
  finishedAt: '2018-04-10T14:58:20.348Z',
  status: 'SUCCEEDED',
   { origin: 'API',
     clientIp: '',
     userAgent: 'ApifyClient/0.2.7 (Darwin; Node/v8.9.4)' },
   { workersUsed: 1,
     durationMillis: 9182,
     runTimeSecs: 9.182,
     readyTimeSecs: 0.01,
     initTimeSecs: 1.219,
     computeUnits: 0.0025505555555555555 },
   { useCache: true,
     betaPackages: false,
     memoryMbytes: 1024,
     diskMbytes: 2048 },
  readme: null,
  buildNumber: '0.1.1' }
Success: Actor was deployed to Apify platform and built there.

And that's it, your first actor was pushed to Apify!

Thanks for reading this article, I hope you found it useful. If you're missing something, you can create an issue on the GitHub repo or contact us through chat.

Did this answer your question?