First, make sure you have Node.js version 7.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 7.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.

VERSION
  apify-cli/0.1.5 darwin-x64 node-v8.9.4

USAGE
  $ apify [COMMAND]

COMMANDS
  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)

❯ Basic ("basic")

  Puppeteer ("puppeteer")

  Puppeteer crawler ("puppeteer_crawler")

  Plain request urls list crawler ("plain_request_urls_list") 

Let's choose a "Basic" 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!

Done.

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 https://my.apify.com/account#/integrations

? 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 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 },
  versions:
   [ { versionNumber: '0.1',
       buildTag: 'latest',
       envVars: [],
       sourceType: 'TARBALL',
       tarballUrl: 'https://api.apify.com/v2/key-value-stores/KX8dsJEQXctEF/records/my-test-0.1.zip?disableRedirect=true' } ],
  defaultRunOptions: { build: 'latest', timeoutSecs: 3600, memoryMbytes: 512 },
  exampleRunInput:
   { 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',
  meta:
   { origin: 'API',
     clientIp: '176.101.147.225',
     userAgent: 'ApifyClient/0.2.7 (Darwin; Node/v8.9.4)' },
  stats:
   { workersUsed: 1,
     durationMillis: 9182,
     runTimeSecs: 9.182,
     readyTimeSecs: 0.01,
     initTimeSecs: 1.219,
     computeUnits: 0.0025505555555555555 },
  options:
   { 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?