Skip to content
Johan Hernandez edited this page Nov 23, 2011 · 1 revision

Getting Started with Fire.js

Once that you installed the runtime you are ready to develop fire.js applications. Let's start with the mandatory "Hello World" example.

Open your favorite text editor and create a blank text file with name HelloWorld.Main.fjson.

Note: It's highly recommended to create a separate directory for each app or project.

Notice how the extension of the file is 'fjson', this is because the file will not contain a regular JSON document, it will contain a "Fire.js JSON Expression" definition.

Now, paste the following JSON document in the file:

{
	"name": "HelloWorld.Main",
	"json": "Hello World!"
}

Save the file changes and open a terminal in the directory where the file resides and run:

npm install fire

That will install the fire runtime inside the node_modules directory.

Note: You must invoke npm without -g or --global because our intention is to install the package locally for our application. This is necessary even if you installed fire.js globally like we suggested in the installation instructions.

Once it's finished you should have a folder called node_modules with a directory called fire inside, by now the directory of your project should look like this:

HelloWorld.Main.fjson
node_modules
 - fire

Now we can run the app using the firejs tool:

firejs HelloWorld.Main.fjson

You should see the following output in the console:

"Hello World"

Congratulations!, you've executed your first JSON application.

Working with package.json

For the purpose of this tutorial we've tried to keep things very simple for you so far, however, installing package manually and specifying the main file to execute is not the best practice when developing fire.js applications. Why? Because we should be using a package.json file instead. A package.json file contains all the relevant information of about the app and it's dependencies.

Let's get rid of the node__modules directory:

rm -rf node_modules

Now let's create a package.json file(and yes!, this time is .json and not .fjson) and paste the following JSON document:

{
	"name": "HelloWorld",
	"version": "0.0.1",
	"dependencies": {
		"fire": ">= 0.1.0"
	}
}

Install the dependencies of our app:

npm install

That should get you install the fire runtime back in the node_modules directory like you had before.

Follow the same routine the next time you need to add a new dependency for your app:

  1. Delete the node_modules directory
  2. Perform npm install

Back to our package.json file, notice how we specified the name of the app using the name attribute. This will define what the name of the main expression looks like for the firejs tool, it basically follows the the pattern "<application-name>.Main". We already have an expression called HelloWorld.Main(remember the file HelloWorld.Main.fjson?) so the app is ready to be executed, this time, by using the package.json file:

firejs package.json

That should give the same output to the console:

"Hello World"

Thanks for Reading. Please take your time to read other tutorials.

Contributors

If you find any error in this tutorial(misspelling errors, syntax errors, etc) please send me an email with your corrections, I'll be more than happy to add you in this list.