Nodal.js and you
So you may love Node and building servers or have a favorite database you use or love to seed. What if I told you, you could do pretty much all of this in 3 lines of code. Yup, 3 lines. Nodal can do all of this for you.
What do I need to make this work?
As software engineers, we have to be aware of dependencies. Another way this plays in is with abstractions on top of things you already use. An example of this would be Nodal sitting on top of Node / n and PostgreSQL. So guess what we need. Yup, Node a stable version of n so we can go back and forth between versions and of course we need a database and PostgreSQL plays nicely with Node.
Ok, what’s next?
Now it’s time to fork and clone down Nodal so we can start our first Nodal project. We can do this by going to github and forking this repo. https://github.com/theethiopian/nodal.
The beautiful thing about Nodal. Well there’s a lot. A few things are the fact that the documentation is great and you can get all the commands you need via the CLI via node help.
We’re getting ahead of ourselves let’s cd into the directory we want to go into and store nodal. We will use our friend npm. Here is the list of commands and steps
- Download and install the newest Node 6.x version from nodejs.org
- Open terminal, and type npm install nodal -g. (If you get an error, run sudo npm install nodal -g or fix permissions permanently by following these directions
- Using your terminal, visit your projects folder. Perhaps with cd ~.
- Run nodal new.
- Follow the on screen instructions, enter your new project directory and type nodal s.
- That’s it! Your Nodal webserver is up and running.
No, really that’s it.
Your server is up now. Let’s add a db for our server. We’ll use PostgreSQL like I said earlier. Here is the list of those steps:
- Once Nodal is up and running, it’s likely that you’ll want to connect your project to a database. Nodal comes packaged with Migrations, a Query Composer and full PostgreSQL integration.
- First you’ll need to install PostgreSQL. OS X users, I recommend using Postgres.app for your development environment.
- Once you’ve installed Postgres, make sure to run:
- $ createuser postgres -s
- To create a default postgres superuser with no password. (Default for Nodal’s configuration.)
- To begin using your database, start with:
- $ nodal db:create
- To create the database and then,
- $ nodal db:prepare
- To prepare for migrations.
- From here, nodal db:migrate runs all pending migrations and nodal db:rollback will roll back migrations, one at a time by default.
Well, now what?
So that’s it. You’re all done and you have a connected server and database. So go build something awesome! You can also use Polybit, a baked in deployment tool, to deploy your API. Type in Nodal help into the CLI and you’ll get all of the nodal commands and their functions.
Ps. If you wanna check out some slides I showed on Nodal you can check them out here: https://youtu.be/GbhjkCUel2A