Command Line Interface to Parse Server

Command Line Interface to Parse Server

The powerful Command Line Tool you’ve been using on Parse.com is now available at Back4App. You can continue to interact with your Parse Server using the Terminal. The Back4App CLI(command line interface) can be used to perform various actions on your Parse App like to create a new app, develop and deploy cloud code, manage app releases, set the SDK version, etc.

Let’s see an example of how simple is creating an App using CLI.

At this example we will create a new empty app on Back4App with a simple cloud function: hello that return: Hello World.

You can create a new Back4App app using the command: b4a new It asks you a series of questions, and at the end of it, you will have a new Back4app app (with the given name). Additionally, you will also set up a Cloud Code project for the app. You can test that everything works by performing and executing: b4a deploy curl command printed at the end of the output.

1.Install your Back4App CLI

MACOS and Linux

In Mac OS X and Linux/Unix environments, you can get the Back4App Command Line Tool by running this command:

curl https://raw.githubusercontent.com/back4app/parse-cli/back4app/installer.sh | sudo /bin/bash

This installs a tool named “b4a” to class=/usr/local/bin/b4a. There’s no other junk, so to uninstall, just delete that file. This will also update your command line tool if you already have it installed.

Windows

The Back4App command line interface for Windows is available at Github Repository.

Please download the b4a.exe file.

b4a_exe_file

Now, we are going to manually install the downloaded program

  1. Open the folder where b4a.exe file is;
  2. Copy the file b4a.exe;
  3. Paste the file on C:\windows\system32 path.

NOTE: b4a.exe is not an installer, it is just a plain Windows executable.

2.Connect your Back4App account to CLI

Account Keys are personal access tokens that can be used to create a new Back4App app and list properties and keys for the given Back4App app. You can configure the command line interface to use account keys to perform various actions like creating a new app and fetching master key for an app when required (for instance, when performing deploy, fetching logs, etc.).

After logged at Back4App go to your account menu and click over Account Keys:

account_key_menu

Write your key name (1), add this to your key list (2) and then save the key (3).

new_account_key

You have a new Key!

Now, go to your terminal and type b4a configure account key. Enter your key and press enter.

$ b4a configure accountkey

Input your account key or press ENTER to generate a new one.
NOTE: on pressing ENTER we'll try to open the url:
	"https://www.parse.com/account/keys"
in default browser.
Account Key: Vh5c3kRbzUmuLrVrOkvMkio989MmXUVoIeIbjTUC
Note: this operation will overwrite the account key:
 "************************************jTUC"
for email: "[email protected]"
Successfully stored account key for: "[email protected]".
$ 

3.Create a new Back4App App or connect your existing App

3.1.Create a new Back4App App

Open your terminal and type the next command: b4a new. Then choose if you want to create a new app or connect to an existing app (n). Choose a name to your App and press enter. See the commands printed on your terminal bellow:

$ b4a new
Would you like to create a new app, or add Cloud Code to an existing app?
Type "(n)ew" or "(e)xisting": n
Please choose a name for your Parse app.
Note that this name will appear on the Back4App website,
but it does not have to be the same as your mobile app's public name.
Name: CLI-Back4App

Now we are going to add cloud code to your App. Choose a Directory name to store locally your Code or press ENTER to use your app name as your directory name.

Awesome! Now it's time to set up some Cloud Code for the app: "CLI-Back4App",
Next we will create a directory to hold your Cloud Code.
Please enter the name to use for this directory,
or hit ENTER to use "CLI-Back4App" as the directory name.<enter>

3.2.Connect an existing App

$ b4a new
Would you like to create a new app, or add Cloud Code to an existing app?
Type "(n)ew" or "(e)xisting": e
1:	Live Query
2:	MyApp2
Select an App to add to config: 2
Please enter the name of the folder where we can download the latest deployed
Cloud Code for your app "MyApp2"


4.Create your Cloud directory and add Cloud Code

Now you can create a blank cloud code or press enter to create a standard cloud function: Hello World!

Directory Name:
You can either set up a blank project or create a sample Cloud Code project.
Please type "(b)lank" if you wish to setup a blank project, otherwise press ENTER:<enter> 
Successfully configured email for current project to: "[email protected]"
Your Cloud Code has been created at /Users/alysson/CLI-Back4App.

This includes a "Hello world" cloud function, so once you deploy,
you can test that it works, with the printed curl command.

Next, you might want to deploy this code with:

	cd /Users/alysson/CLI-Back4App
	b4a deploy

Once deployed you can test that it works by running:
curl -X POST \
 -H "X-Parse-Application-Id: 1mbEzX6hH4OBX3lq6QPnJfhOfdSAN6sVte2gzCbv" \
 -H "X-Parse-REST-API-Key: 5EEeLGwkK9SD3d9zJfbtcHXXc4l670Fcu3U6POrI" \
 -H "Content-Type: application/json" \
 -d "{}" \
 https://parseapi.back4app.com/functions/hello

5.Deploy your Cloud Code

Navigate to your cloud code folder and deploy your code using the command: b4a deploy.

$ b4a deploy
Uploading source files
Uploading recent changes to scripts...
The following files will be uploaded:
/Users/alysson/CLI-Back4app/cloud/main.js
Uploading recent changes to hosting...
The following files will be uploaded:
/Users/alysson/CLI-Back4app/public/index.html
Finished uploading files
New release is named v1 (using Parse JavaScript SDK v2.2.25)

Check your function at Back4App. Go to your app > features > Cloud Code > Server:

cloud_code_hello

NOTE: You can use this command to upload all your cloud code files. You just need to transfer those files to your linked directory and use the b4a deploy command.

5.Test your function

Use the given command to run a request on Back4App API and call your hello function:

curl -X POST \
 -H "X-Parse-Application-Id: 1mbEzX6hH4OBX3lq6QPnJfhOfdSAN6sVte2gzCbv" \
 -H "X-Parse-REST-API-Key: 5EEeLGwkK9SD3d9zJfbtcHXXc4l670Fcu3U6POrI" \
 -H "Content-Type: application/json" \
 -d "{}" \
 https://parseapi.back4app.com/functions/hello
{"result":"Hello world!"}

 

What’s Parse Server?

Open-source backend framework used to accelerate mobile app development.

What’s a CLI?

command-line interface (CLI) processes commands to a computer program in the form of lines of text.

How to use Parse CLI?

– Install your Back4App CLI
– Connect your Back4App account to CLI
– Create a new Back4App App or connect your existing App
– Create your Cloud directory and add Cloud Code
– Test your function


Comments ( 11 )

  1. b3n
    Very cool we got the CLI now for back4app. BUT, i cant deploy any cloud code, only the public folder works, as soon i have a cloud folder with files i get: parse: error with status=500 and body="Error: Object {"folder":"cloud","filename":"userflow.js","version":"2","checksum":"564872..82b9c0eec849fe9e9378f1e0"} not found.    at /home/back4app/scm/back4app-cli-server/node_modules/parse-cli-server/lib/ParseCliController.js:114:17    at process._tickDomainCallback (internal/process/next_tick.js:129:7)\n" Can you please help me? Thanks
    • Alysson Melo
      Have you connected your account using the account Key? Did you had previous parse CLI installed on your computer?
      • Ricardo Paiva
        Hi Alysson, I'm also having some issues. The message I get is: at process._tickDomainCallback (internal/process/next_tick.js:129:7) Error generating response. Error: Object {"folder":"cloud","filename":"backgroundJob.js","version":"2","checksum":"aa96fba8f6fdc7fe602efbeb4c6d0dad"} not found. at /home/back4app/scm/back4app-cli-server/node_modules/parse-cli-server/lib/ParseCliController.js:114:17 at process._tickDomainCallback (internal/process/next_tick.js:129:7) I'm using it in MacOS environment. I don't have Parse original CLI installed in my Mac only the B4A CLI and I've just updated to the latest version available. Regards and keep the good work!
        • Alysson Melo
          Try to remove the previous version and install this new version beta-5.
          • Ricardo Paiva
            Hi, Still the same issue. First I get: "Your changes are now live." But then a lot of errors like this: Error generating response. Error: Object {"folder":"cloud","filename":"main.js","version":"2","checksum":"c1beff9b7d7fe62761a85882cb0a4abf"} not found. at /home/back4app/scm/back4app-cli-server/node_modules/parse-cli-server/lib/ParseCliController.js:114:17
  2. Cindy
    I need some help I received an email from y'all saying that the powerful command line tool that I've been using on parse.... I don't understand I don't have a command line on parse.... However with that being said all if my phone data and computer data is going some where else I just don't know where could you please help me figure out what is going on...thank you in advance for your help. Cindy Edwards email [email protected]
    • Alysson Melo
      Cindy, please check this link out : https://web.archive.org/web/20160112010649/https://parse.com/docs/cloudcode/guide#command-line-installation. That was the previous CLI available at Parse.com.
  3. cublah
    ok I got it working with your example main.js file, but when I use the CLI to upload my main.js I get a load of errors, I tried adding function by function and had some success, but eventually same thing, all the functions work and if I upload the file via the website its all good but I can't use the CLI.
  4. TealShift
    Sweet! I just got it up and running. I'd like to point out that 'b4a help' shows me the original parse CLI help document. :U And should I be able to deploy to my development clone app with a 'b4a deploy '?
    • Alysson Melo
      Yes, just connect with the cloned app.
      • TealShift
        It works! For the record I meant to type "b4a deploy (name of clone)" and it does indeed work just like the original Parse CLI. Now the only reason I can't use the CLI is because it can't handle uploading the files I have in my "public" directory for webhosting. The error was already reported on the forum, so I look forward to a fully functioning version. :)

Leave a reply

Your email address will not be published.