DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Data Engineering
  3. Databases
  4. The Express-Starter in a Structured Way

The Express-Starter in a Structured Way

In this article, we cover how to create an application that will fetch movie names from an unstructured, PostgreSQL database.

Sibu Stephen user avatar by
Sibu Stephen
·
Jul. 03, 17 · Tutorial
Like (3)
Save
Tweet
Share
5.24K Views

Join the DZone community and get the full member experience.

Join For Free

Why Express Starter?

Normally boilerplates like MEAN.io or MEAN.js  or any other, use MongoDB or some other unstructured database.

Using unstructured databases provides the developer with the ability to manipulate the database in JSON format. Well, the mapping part is a bit tricky when it comes to unstructured databases, and the manipulation of structural databases can be made easier by querying the necessary info (for example – select * from tableName). In such cases, great results can be achieved when we use Node.js with the structured database, PostgreSQL.

Express Starter provides you with a view using Angular and Express.js for routing, and Node.js on the back-end, along with that the storage partner PostgreSQL.

express2

Codebase Example (With Relation to Mapping)

The following example shows fetching a list of movie names right from a database to your view. 

1.)  Inside Model (Schema/Sequelize) 

module.export = function(db, DataType) {

    var movieList = db.define(‘movies’, {

        id: { ‘Provide the dataType and other attrbiutes over here’},

        movieName: {‘Provide the dataType and other attrbiutes over here’}

    });

}

2.) Inside Repository

var repo = {}; //Empty object

var db = require(‘Path to sequilize file which we made’); // call the db object which indirectly calls the sequilize schema object called(‘movieList’).

repo.movieList = function() {

    var returnMovie  = db.movieList.findAll();

        return returnMovie;

}

3.)  Inside Controller

var db = require(‘path to db defined in sequilize’);

var movieRepo = require(‘Path to Event Repo’);

exports.movieListController = function(request, response) {

movieRepo.movieList().then(function( movieName) {

    res.render(‘/moviesList’, { movieDisplay: movieName});

});

}

4.)  Inside app.js (Mapping Controller With View)

    var express = require(‘express’);
    var app = express();

    var movieController = require(‘Path to the controller which we made previously’);

app.post(‘/event’, movieController.movieListController) ; //Mapping the views with the controller by sending an api(using POST request).

5.)  Mapping the Movie Names With the movieDisplay.ejs File (Displaying Movie Names).

<form method=”post” action=”/moviesList”>

<div><%= movieDisplay.movieName  %>

</form>

Folder Structure (From the Route Directory)

Config – Configuration for a passport or any other secret key that needs to be provided.
Controllers – Logical arena where the mapping between the models occurs (by exporting the repositories) and where we call it in view.
Migrations – Creating tables using the schema’s provided in the model.
Public – Contains a list of all Stylesheets, Images, and JavaScript for the view.
Repositories – Contains individual files for each module consisting of querying in order to fetch the appropriate data.
Seeders – Made up of 'by default values' which need to be set in the individual records. For example, if we need to assign a username and password (master username and password), this allows us to seed the created username/password record so that it’s fetched right away.
Services – Consists of the services (Generic functions) which we need to use in our various controllers.
Views – Consist of .ejs files with the main file named layout.ejs, wherein we import the other sub .ejs files.
app.js – Route for the controllers to be sent to the views (the entire mapping is done here).
package.json – Necessary modules can be installed using npm. 

About the Existing Project Made in Express Starter 

An internal CRM for all employees wherein employees can apply, leave, see events, and more. Having 4 roles involved (Including – Admin, HR, Manager, Employee) the project is under development with new features coming up.

For any query with relation to express starter, you guys are most welcome to view my GitHub repo.

Happy expressing!

Database Express

Published at DZone with permission of Sibu Stephen. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Key Elements of Site Reliability Engineering (SRE)
  • Java REST API Frameworks
  • Custom Validators in Quarkus
  • HTTP vs Messaging for Microservices Communications

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: