About Bedrock

Bedrock lets you set up a production-ready Node web application in under 10 minutes. It is a collection of popular frameworks that work well together. It is great for dashboards, CRUD webapps, and more.

Features

The main features of Bedrock are:

User authentication setup in under 10 minutes

React Hot Loading for super fast frontend development with React and Flux

A server with all the features you need to get to production quickly and securely

The list below has some more details.

Server-side Features

Bedrock is built on Sails, which is a popular MVC Framework that is built on Express. It has all of the great features that Sails ships with, such as:

Reusable Security Policies (Middleware)

Configurable via a global sails.config object.

object. Encourages use of reusable services.

Waterline ORM that works well with multiple popular databases such as MySQL, Postgres, Mongo, etc.

Follows MVC conventions, which keeps your code organized as your project grows.

Auto-generates simple REST APIs based on your models, using Blueprint.

It is just an Express server under the hood, so all Express modules still work.

Check out all the features on the Sails documentation page.

On top of the Sails features, Bedrock adds in a few nice-to-haves on the server side:

All the code you need to setup user authentication flow

Support for Database Migrations

Configure the server for various NODE_ENV such as development, staging, and production

Frontend Features

Bedrock hooks up React, Flux, and React Router to make frontend development very enjoyable. Here are the features that you get:

React Hot Loader enabled to enable super-fast development of React components without page refreshes, while saving your component state.

React Router to help you build efficient front-end routing.

File and folder structure for building front-end components with React and Flux.

Webpack is used to watch and build the JavaScript and chunk it so pages don’t end up with unneccessary code.

You can learn more about Bedrock’s frontend stack on the Frontend Development with Bedrock page.

Quickstart

Bedrock is the starting point of your Node application. To install, you should clone the project, and then build on top of it.

git clone ... < project -name> cd < project -name> npm install

Configure Database Connection

Go into config/connections.js . Update the mysql connection details. At this point, you may need to create a new database.

If you want to use a different database (PostgreSQL or Mongo), remove the mysql connection, and create a new connection, as shown in the comments in the file.

If you don’t want any database, you can just remove everything in config/connections.js but understand that user authentication won’t work.

Migrate database tables

Bedrock sets up authentication for your server, and creates Login, Signup, and Reset password pages. It uses PassportJS to accomplish this.

To facilitate this, you need to run a migration to create the Users and Passports table. Just run this from the command line:

grunt db :migrate :up

npm start

After it runs, check your database and you should see `Users` and `Passports` table created. We will talk more about migrations in the Best Practices section. ### Run servers in development mode To start developing, run:

This will start up 3 things:

An Express server on Port 1337. This is the primary NodeJS server.

A Webpack Dev Server on Port 3000. Any static assets will be served by Webpack in development mode. This allows for Hot Module Replacement.

Assets will be built by Webpack, and a watch task will be started. Any CSS and JS changes will trigger a new incremental build.

Run servers in production mode

In production mode, you’ll want to build your assets ahead of time. To do this, run:

grunt buildProd

This will build your assets and store it in the www/ directory.

Then, you can run your server in production mode:

NODE_ENV =production sails lift

This will start up the NodeJS server in production mode. If you want this to be a long-lived background task, consider using a Node Process Manager like pm2.

Built With

Bedrock is composed of these open-source frameworks.

Sails: Sails makes it easy to build custom, enterprise-grade Node.js apps. It is designed to emulate the familiar MVC pattern of frameworks like Ruby on Rails, but with support for the requirements of modern apps: data-driven APIs with a scalable, service-oriented architecture

React: A JavaScript Library for building user interfaces

React Router: React Router is a complete routing library for React.

NuclearJS: Traditional Flux architecture built with ImmutableJS data structures. Very similar to Redux.

Webpack: A module bundler for front-end assets. It is used in Bedrock for chunking JavaScript files to be loaded on demand.

React Hot Loader: Tweak React components in real time without page refreshes.