Lua on Beans

Getting Started with Lua on Beans

1. Install luaonbeans-cli

First, you need to install the Lua on Beans CLI globally using npm:

npm install -g luaonbeans-cli

2. Create a New Project

Once the CLI is installed, you can create a new empty project using the following command:

beans new my-project

Replace "my-project" with your desired project name.

3. Set Up ArangoDB

Lua on Beans uses ArangoDB as its database. You can easily set it up using Docker Compose:

  1. Ensure you have Docker and Docker Compose installed on your system.
  2. Navigate to your project directory in the terminal.
  3. Run the following command to start ArangoDB in detached mode:
docker compose up arangodb -d

Alternative Database Options

While ArangoDB is the default database for Lua on Beans, it's important to note that you have other options:

  • No Database: Lua on Beans can be used without a database for static sites or applications that don't require data persistence.
  • Other Databases: The framework is designed to be flexible. With some configuration, you can use other databases like PostgreSQL, MySQL, or MongoDB.

To use Lua on Beans without a database or with an alternative database, you'll need to adjust your configuration and potentially create a custom database adapter. Refer to the advanced configuration documentation for more details on setting up alternative database solutions.

Next Steps

With these steps completed, you now have a new Lua on Beans project set up with ArangoDB running. You're ready to start building your web application!

Check out our documentation for more information on how to structure your project, create routes, and interact with the database.

4. Configure Database Connection

To connect your application to ArangoDB, you need to configure the database settings. Follow these steps:

  1. Navigate to the config folder in your project directory.
  2. Locate the database.json.arangodb.sample file.
  3. Create a copy of this file and rename it to database.json.
  4. Open database.json in your preferred text editor.
  5. Update the file with your ArangoDB connection details. Here's an example configuration:

{
  "system": {
    "db_name": "_system",
    "url": "http://127.0.0.1:8529",
    "username": "root",
    "password": "password"
  },
  "development": {
    "db_name": "luaonbeans_dev",
    "url": "http://127.0.0.1:8529",
    "username": "root",
    "password": "password"
  },
  "production": {
    "db_name": "luaonbeans",
    "url": "http://127.0.0.1:8529",
    "username": "root",
    "password": "password"
  },
  "test": {
    "db_name": "luaonbeans_test",
    "url": "http://127.0.0.1:8529",
    "username": "root",
    "password": "password"
  },
  "engine": "arangodb"
}

5. Create the Database using ArangoDB UI

Now that you've configured your database connection, you need to create the actual database in ArangoDB. Follow these steps to create the database using the ArangoDB UI:

  1. Open your web browser and navigate to the ArangoDB UI (typically at http://localhost:8529 if running locally).
  2. Log in using your ArangoDB credentials (default username is "root") and select the "_system" database.
  3. In the left sidebar, click on "DATABASES".
  4. Click the "+ Add Database" button in the top right corner.
  5. Enter the name of your database (e.g., "luaonbeans_dev" for development).
  6. Click "Create" to create the database.

Repeat this process for each environment (development, production, test) you've defined in your database.json file.

6. Run the Lua on Beans App

Now that you've set up your database, you're ready to run your Lua on Beans application. Follow these steps to start your app:

  1. Open your terminal or command prompt.
  2. Navigate to your project's root directory.
  3. Run the following command to start the Lua on Beans server:
    ./luaonbeans -D .
  4. You should see output indicating that the server has started successfully. The output will look similar to this:
    I2024-09-29T19:10:06.510903:tool/net/redbean.c:1122:luaonbeans:41737] (cfg) program directory: .
      I2024-09-29T19:10:06+031026:tool/net/redbean.c:7052:luaonbeans:41737] (srvr) listen http://127.0.0.1:8080
      I2024-09-29T19:10:06+000057:tool/net/redbean.c:7052:luaonbeans:41737] (srvr) listen http://192.168.10.118:8080
      I2024-09-29T19:10:06+000111:tool/net/redbean.c:7052:luaonbeans:41737] (srvr) listen http://192.168.165.0:8080
      I2024-09-29T19:10:06+000047:tool/net/redbean.c:7052:luaonbeans:41737] (srvr) listen http://198.19.249.3:8080
      I2024-09-29T19:10:06+000030:tool/net/redbean.c:7052:luaonbeans:41737] (srvr) listen http://192.168.229.0:8080
      I2024-09-29T19:10:06+000028:tool/net/redbean.c:7052:luaonbeans:41737] (srvr) listen http://172.18.0.0:8080
      I2024-09-29T19:10:06+000029:tool/net/redbean.c:7052:luaonbeans:41737] (srvr) listen http://192.168.164.0:8080
      >:
      
  5. Open your web browser and navigate to http://localhost:8080 (or one of the other IP addresses listed in the output).
  6. You should now see your Lua on Beans application running

Congratulations! You've successfully set up and run your Lua on Beans application. You can now start building your web application using the power of Lua, redbean.dev, and ArangoDB.