Lesson 03
Overview of the Sails App Structure
Summary
Sales.js Project Structure Overview
In this lecture, we explore the structure of a project generated by Sales.js 0.12, specifically the Sales Quick Start project created previously.
Key Components of the Project Structure
-
Root Directory:
- Contains
package.json
, defining it as a Node.js project. - Entry Point:
app.js
serves as the application's main entry file. - Grunt File: Used for asset management tasks.
- Contains
-
Directories:
- API Directory: Holds sub-directories for:
- Controllers: Contains controller files.
- Models: Contains model files.
- Services: Includes helper methods and additional functionalities.
- Assets Directory: Stores static files such as:
- JavaScript files
- Stylesheets
- Images
- API Directory: Holds sub-directories for:
-
Tasks Directory:
- Contains files for Grunt tasks.
-
Pipeline Configuration:
pipeline.js
is used to set up script injections into view files.
-
Views Directory:
- Default template engine is EJS (can be changed to alternatives like Pug).
- Contains:
layout.ajs
: Main layout file.- Additional pages (e.g.,
homepage.ajs
). - 404 and error templates.
-
Configuration Directory:
- Holds files for:
- Database configuration
- Environment configuration
- Middleware
- Custom routes (
routes.js
) - Data sources (
connections.js
): Defines databases used (e.g., disk adapter for development).
- Holds files for:
-
Environment-Specific Configurations:
- Located in
config/
for different environments (development, production, etc.). - Allows selection of database types based on the running environment.
- Located in
Conclusion
This lecture provided an overview of the structure of a Sales.js application, highlighting the organization and purpose of each directory and file. The next session will delve deeper into implementation details.
See you in the next lecture!
Video Transcript
In this lecture we're going to look at the app structure for the project that is generated by sales 0.12.
So in the last lecture we created this project called Sales Quick Start.
And then here's the listing of all the files in this directory.
Let's switch to the Finder to see it visualizes better.
So sales is going to create a package.json because it is a node project.
Okay? And then the entry point for the application is this file called app.js.
Because sales uses Grants for some of its tasks related to asset management, there's a Grant file.
Now the directories. So we have an API directory that is going to contain directories for the controllers, models,
services and other stuff. Okay? Controller, model and other stuff like services.
We have this assets directory.
Assets directory is for like things like images, JavaScript files and style sheets.
We have JS, styles, okay? And images.
So we have this tasks directory is mostly for grunt tasks.
Okay? You can take a look if you want.
Now there's a file called pipeline.js.
That's where you're going to set up your pipeline to inject scripts in your Vio files.
Okay? This is not that useful if you were making an API only without the view.
All right?
And then we have the directory for the views.
And by default it uses EJS but you can change it to anything you'd like.
For example, Jade, which is now called pug and things like that.
All right? So layout.ajs is the layout and then you can inject a page like homepage.ajs in the layout.
And these are the 404 and other error pages, templates. All right?
So this is the structure of those sales application.
So let's open here the text editor.
In this case I'm using Adam.
So take a look at more closely at the most important parts.
So we already had an overview.
So mostly you want to see also the config directory I forgot to mention.
This directory here is where you're going to do all your configuration, database configuration, environment configuration, middleware, routes and so on.
So inside the configuration here there's this file called routes.js.
This is where you're going to set up your custom routes. All right?
config slash routes.js.
There's also this file called connections.js, very important.
So you can set your data sources here.
You can define what kind of databases to use.
By default it uses this what's called an adapter.
So sales has many adapters for different kinds of databases.
This is called the sales disk adapter and is meant for development only.
So it's a local disk database.
Okay, so config slash and is where you set up the environment specific configuration.
So typically here you can choose which connection to use.
For example, in development I could use just a local disk database,
but in production I would use some other database like my Am I a screw L or MongoDB or something else.
So you can change what kind of database depending on the environment using these files.
config slash and slash development, production or anything else.
You can just create a file here to define your own environment.
All right, it doesn't have to be that those environments.
So these are environment specific files.
And there's other files here that also has more configuration.
Now going back here, we had an overview and just going again to the API directory.
This is where you're going to see your controller directory where all your controllers are going to be.
API slash models where all your models are going to be.
If you need to set up services that is helper methods, you can put it in the services directory.
There are also other stuff like policies and responses.
All right, so this was an overview of the application structure of a sales.js file project.
See you in the next lecture.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: