part-0.jpg

Learn Sails.js - Part 0

🛈

Welcome back! I hope you will enjoy the next few posts introducing the Sails.js web framework. To make it more fun I thought I make it into a little RPG like game. So let’s get started with part 0 which is more of a pre-stage to make your system ready for Sails.js.


Pre-Voyage Checklist: The Shipyard

  • Rank: Civilian
  • Objective: To ensure you are properly equipped, understand the mission, and have the foundational knowledge to begin your voyage with Sails.js.

The Captain’s Briefing (Background and Theory)

Welcome to the shipyard, future Captain. Before you can command a fleet, you must first understand the vessel. A modern web application is a complex machine, and building one from scratch using only raw materials is a monumental task. You would need to forge every screw, mill every plank, and weave every rope yourself. That is the world of coding without a framework.

This is where your master blueprint, Sails.js, comes in. Sails is a web framework. Think of it as a master-crafted ship kit. The hull’s design is already laid out, the key structural components are pre-fabricated, and there’s a logical set of instructions for assembling everything. This lets you focus on the important parts, the cargo you’ll carry, the routes you’ll travel, and the unique features of your ship, rather than on the basics of naval architecture.

The Engine Room: Node.js and npm Your ship will sail on the vast “Digital Sea,” which is powered by Node.js. Node.js is a runtime environment that allows you to run JavaScript code on a server, outside of a web browser. It’s the engine that will power your entire application.

Every engine needs parts, fuel, and tools. For Node.js, that supply store is npm (Node Package Manager). It’s the world’s largest software registry, the grand bazaar where you’ll acquire all the “packages” (pre-written code) you need, including the Sails.js framework itself.

The Master Blueprint: The MVC Architecture Sails.js, like many professional frameworks, is built upon a time-tested architectural pattern called MVC (Model-View-Controller). Understanding this is the single most important concept for your journey. It’s how your ship is organized.

  • M - Model (The Cargo & The Manifest): The Model is responsible for all your application’s data. It is the ship’s cargo hold and, more importantly, the cargo manifest. It defines the rules for your data: what kind of cargo (or “data”) can you carry? What are its properties (e.g., a user has a name and email)? How is it stored? The Model is your single source of truth for everything data-related.

  • V - View (The Ship’s Appearance): The View is what people see. It’s the polished deck, the painted hull, the sails snapping in the wind, and the flag flying from the mast. In web terms, this is the user interface (UI), the HTML, CSS, and front-end JavaScript that gets rendered in the user’s browser.

  • C - Controller (The Captain on the Bridge): The Controller is the brain of the operation. It’s the captain standing at the ship’s wheel. When an order comes in (an HTTP request from a user, like clicking a link), the Controller is the one who interprets it. It might command the Model to fetch or update data from the cargo hold and then command the View to display the results. It connects the user’s actions to the application’s data.

By separating these three concerns, Sails keeps your code organized, scalable, and much easier to manage.


Key Concepts Checklist

  • Node.js: The JavaScript server environment.
  • npm: The package manager for Node.js.
  • Web Framework: A structured toolkit for building web applications.
  • MVC Architecture: The Model-View-Controller design pattern.
  • Sails.js CLI: The command-line interface you’ll use to create and manage Sails projects.
  • Convention over Configuration: The principle that the framework makes smart default choices for you, speeding up development.

Mission Log: Quest - “Sign the Ship’s Articles”

This quest ensures your development environment is correctly set up and you’ve understood the core principles.

  • Task 1: Procure Your Engine (Install Node.js & npm)

    1. Navigate to the official Node.js website.
    2. Download and install the LTS (Long Term Support) version for your operating system. npm is included automatically with the Node.js installation.
    3. Verify the installation: Open your computer’s terminal or command prompt and run the following two commands, one after the other. You should see version numbers output for each.

      node -v
      npm -v
      
  • Task 2: Acquire the Master Blueprints (Install Sails.js)

    1. In your terminal, run the following command to install the Sails.js package globally on your system. The -g flag makes the sails command available everywhere.

      npm install -g sails
      
    2. Verify the installation: Run the sails version command.

      sails -v
      

      You should see the version number of your Sails installation.

  • Task 3: Take the MVC Oath (Prove Your Knowledge)

    1. Open a simple text file or grab a piece of paper.
    2. Without looking back at the briefing, write one sentence for each of the MVC components, describing its role using the ship analogy.
    3. This is for your benefit only, a mental check to ensure the core concept is clear before we start building.

Mission Debrief (Review & Outcomes)

Excellent work. You have successfully provisioned your shipyard. Your local machine is now a fully-featured development environment, equipped with the runtime, package manager, and framework blueprints necessary for the journey ahead.

Most importantly, you now understand the fundamental MVC pattern that governs our work. This separation of concerns is the key to building clean, powerful applications.

Your tools are ready. Your mind is prepared. The next step is to use those blueprints to construct your very first vessel.


Rewards & Promotion

  • +50 Doubloons
  • Promotion to: Seaman

Welcome aboard, Seaman. Your voyage begins now.