Example: Create and deploy a project with a single action
Let’s start with a really simple example that shows the basics of creating the source code for an action, placing it in a directory structure for a project, and deploying the project. This project needs no configuration and creates actions automatically based on the project directory structure.
In the simplest implementation of a project, each action corresponds to a single source file. In this example:
Hello Worldprint function is placed in a file named hello.js.
- A project named
example1is created and deployed to your namespace.
To create and deploy a project to print Hello World (simplest form):
So, what just happened? As a result, of
nim project create,
nim generated a project and added a sample to it called
hello.js. Specifically, in your current directory, it created
We address the purpose of the
web directory in Adding static web content and the
packages directory later in this section.
As a result of
nim project deploy, the project was deployed to your namespace and the result was an action called
hello. To record the status of that deployment,
nim action invoke step invoked the just-deployed action.
nim project create command has some other features that will come up in other examples. But,
nim project create is only a convenience.
To make the process less magical and more hands-on, remove the entire
example1 from your local filesystem and let's start over, without using
nim project create, emphasizing that a Nimbella project, no matter how it is created and modified, is just an area in your local file system.
Create and deploy a project to print Hello World (more manually):
(1) Create hello.js with the following code:
(2) Create a project directory with the following command:
The project directory structure sets the name of the project (
example1), a packages directory, and the package qualifier (
demo). There is no
web directory this time;
web is not required if you aren't adding web content.
demo directory with the following command.
(4) Deploy the project.
(5) Invoke the deployed action.
Here’s a diagram of the project structure that was created in this procedure.
project deploycommand activates the deployer, which names the action automatically based on the source code file (
hello), prepended by the package qualifier (
- If you want an action to have a simple name (no package qualification), put it in a package directory called default. In that case, no package qualifier is prepended. See Project Directory Structure. When
nimgenerates a sample in
nim project createit uses this feature.
- The correct runtime for the source code file is determined according to the file suffix. The command
nim info --runtimeswill list the supported runtimes. At this time, the list does not include file suffixes. See Nimbella Deployer Supported Runtimes for Actions for a list that includes suffixes.
- Project configuration occurs automatically when it can, but see Adding Project Configuration for complex projects.
- To add web content to your project, see Adding static web content.
- If you need to add build steps, see Incorporating build steps for actions and web content.
- Read more about deploying projects.
- Look at a somewhat more complex example QR code project with both an action and static web content.