Skip to content

ryan-haskell/lawyer-and-sons

Repository files navigation

Lawyer and Sons

A full site build using KeystoneJS, MongoDB, and Docker

Features

  1. Get up-and-running with one command (docker-compose up)
  2. Runs on all platforms (Windows, Mac, Linux)
  3. No need to download/restore database
  4. Save the file, refresh the page.

Local Development

  1. Install Docker
  2. Run docker-compose up
  3. Your site is ready on port 3000!

Signing in to KeystoneJS

For local development, an account has been created for you.

Username: admin@keystone.com

Password: password


Customizing your Environment

Just create a .env file in the project root.

Environment Variable Description Example
MONGO_URI MongoDB connection string mongodb://localhost/db
NODE_ENV Specifies whether we're running in production or development mode. production
CLOUDINARY_URL Points to the Cloudinary Image service. cloudinary://api_key:api_secret@cloud_name
PORT Which port to host the server on 3000
COOKIE_SECRET Used for encryption 23r2fm24f4fp23f23f

Example .env file:

MONGO_URI=mongodb://192.168.99.100/some-database
PORT=1234

Project Structure

Item Description
app.js Entry point to the app (start here)
routes.js Defines routes for the website
routes/ Functions that handle requests, middleware, and responses
models/ Stores all the KeystoneJS models
views/ Stores layouts, pages, and components used on the site
public/ Assets (sass, images, etc) for our site
logic/ Reusable functionality that is used by multiple routes
updates/ Initializes empty databases (no more downloading backups)

Project Overview

After you install Docker and pull this code, you will have everything you need to get started.

Opening up a terminal and typing docker-compose up will automatically set up an isolated development environment. This command does a few simple things:

  • Creates a local MongoDB container (stores data).
  • Creates a local NodeJS container (runs server).
  • Connects them together so they can communicate.
  • Runs your NodeJS website at http://localhost:3000

When you first run this project, KeystoneJS will automatically create MongoDB collections from the JSON found in the updates/data folder. This means there is no need to download or restore your databases.

After that, you can login at http://localhost:3000/keystone to manage content, or open up your favorite text editor to start changing code.

When you change a model or a route, the server will automatically refresh for you.

The server will also refresh if you modify any logic, updates, or either the app.js or routes.js files.

For frontend development, we are using Pug templates in place of HTML, and SASS in place of CSS.

Once again, changes to these files will automatically and immediately reflect on page refresh.

Instead of bundling all of our Javascript into one big, minified blob, we are using pug to only include the JS we need for the page.

The JS framework used for this project is VueJS. It is as simple as jQuery with the scalability of React and Angular. Just like our Pug and SASS, any client-side JS changes will automatically appear on the frontend.

Docker made it easy to guarantee a consistent, automated environment. Now you can focus on the human part: Actually writing code, fixing bugs, and adding features.


New to NodeJS?

What's great about NodeJS is that you can follow everything by starting in the app.js.

There are no hidden configuration files to worry about.

Keep an eye out for the require method, which will lead you right to the file with the code.

What does require() do?

Here's a simple example:

app.js

var someString = require('./exportsSomeString.js');

console.log(someString);

exportsSomeString.js

var hiddenString = "I'm a secret!";
var otherString = "Hello!"

module.exports = otherString;

This would output:

> Hello!

The module.exports decides what will be returned when require is called.


More documentation to come!