We will be building a “Micro-Blogging” type application. We will call our app Clover. This app allows a user to create an account, then log in and post “Fortunes” which will be small snippets of text. For example, words of wisdom, pop culture references, or good luck wishes!
A user will be able to view fortunes written by other users.
This tutorial will cover the following items:
If you haven’t installed Lucky yet, head over to the Installing Crystal and Lucky guides, first.
Before we begin, a few assumptions will be made about you, and your skill level. If at any point you feel confused or lost, or just need clarification, please chat with us so we can clear things up. We love to help!
We assume you have…
crystal -vshould be at least 1.6.0 or higher
lucky -vshould be v1.0.0.
psql --versionshould be
node -vshould be
From your terminal, we will start the Lucky wizard to generate our application. Run the
lucky init command:
This will ask us what “Project name” we would like to use. We will call it “clover” in all lowercase. Enter
Project name?: clover
Next, the wizard will ask us which format of application we would like to build. We are building a “full” app
API only or full support for HTML and Webpack? (api/full): full
Lastly, the wizard would like to know if we want to generate authentication. We do! This will give us the ability
to create user accounts and login/out of our accounts. Enter
Generate authentication? (y/n): y
Once that’s done, Lucky will give you a few instructions on what to do next. We will follow those instructions in the next step.
For more information on the wizard, read the Starting a Lucky Project guide.
Before we boot our application, we still need to complete the setup process. This portion is specific to the individual as only you will know your own database settings.
Let’s start by changing the directory into the project. Enter
Now we need to make sure we can connect to Postgres so we can run SQL. Open up your Clover app project, and
The default postgres connection uses the username
postgres, and the password
postgres along with the hostname
Look over these settings, and update them to match your own personal setup.
Done? Did you remember to save the file? 😄
For more information on setting up your database, read the Database Setup guide.
Next we will run our setup script. This script does a few things:
Run the setup script. Enter
This may take a bit of time to run. If anything fails at any point, let us know!
If you see the output
Run 'lucky dev' to start the app, then
you’ve officially started your first Lucky project! Now you can run the app, and play with it.
Start the Lucky app. Enter
ctrl-c at any time to stop the server.
There are two separate processes that boot;
web. We must wait for both to finish.
Open up your favorite browser, and head over to
http://127.0.0.1:3000. This URL will be printed
in your terminal log output.
To change the port your app runs on, update the
portoption in the
You should now see the Lucky home page.
Click the “VIEW YOUR NEW APP” button to be taken to a “Sign Up” page. Because the wizard set us up with Authentication, we now have the ability to create a User account, and log in. Make your account!
After you’ve signed up, you are taken to your “Profile” page.
For more information on the application file structure, read the Philosophy and Concepts guide.
Now that you’ve generated a real working Lucky app, play around with it! In the next steps, we will start building out more of the application.
When you’re done, stop your server with
ctrl-Cbefore moving on to the next section.