Gulp:: Getting Deployment Ready: Introduction To Production Environment
Gulp:: Getting Deployment Ready: Introduction To Production Environment
Gulp:: Getting Deployment Ready: Introduction To Production Environment
We have created a huge folder structure wherein different folders are handling different
departments of the code.
anything they want without worrying about it affecting any end-users or content editors
● We need to recall everything that we have done in the project, such as the password
that we have chosen, the secret key generators, etc. We need to keep all this in one
file.
● This file will contain two environments - production and development, for that we
● For now, we will export development and once we fill the production part we choose
● We need to get in different passwords from different files and put them in the
1
● We need a session cookie key inside the { Environment.js } file.
● We need an SMTP object from the nodemailer file inside the development constant.
● We need client id, client secret, and callback URL from the {
passport-google-oauth2-startegy.js } file.
{ Environment.js }
{ index.js }
2
Environment Variables:: Production Environment
● We need to set up the production environment like the way we have set up the
development environment. The only difference is the keys that we can see in the
somewhere in a file on the system and not in the code and that file will be accessed
by the code inside the {environment.js } file so that the developers do not get
debugging.
● When we are in development mode in the terminal we can see the logs and we can
3
● Whereas when we are in the production model, the server runs in the background
● To save the logs in the file we will be using a middleware that will put those logs in
the file but also that file can grow huge, to prevent in growing huge either we create
● We will be using Morgan as a middleware so for that we need to install using the
EXTRA: You can read about morgan from the link below -
http://expressjs.com/en/resources/middleware/morgan.html
● We also need to install that rotating file system that will delete the files when they
grow large. For now, a rotating file system is going to do the task of creating multiple
log files so when one file reaches a specific file size that is defined in the
documentation it will move on transferring that set of files and start filling the
● We need to install a rotating file system using the command { npm install rotating
file system }.
EXTRA: You can read about the rotating file system from the link below
https://www.npmjs.com/package/rotating-file-stream
{index.js}
4
{ Environment.js }
5
Logging for Production
● We need to compress them while sending them to the server to the browser.
● Compress means - any extra space in the files is removed, the variable names are
● To install gulp we need to use the command { npm install --global gulp-cli} and {
● We need to install gulp-sass using the command { npm install gulp-sass } in the
terminal.
● We need to install a package, cssnano, that will compress the CSS into one line using
● We need to install gulp rev that will rename the files with a # alongside them.
● To install gulp rev we need to use the command { npm install gulp-rev }.
● Gulp contains tasks that need to be created and one of those tasks is minifying CSS.
● A pipe is a function that is calling all the sub middleware that is there in the gulp.
● For production mode we need to change the asset path, we need to put it inside the
folder called public, and that public folder will contain assets that further contain the
{ gulp.js }
6
EXTRA: You can read about Gulp from the link below
https://gulpjs.com/
● We have minified the JS and CSS files inside the { gulp.js } file.
{ gulp.js }
7
● Whenever we are building a project we need to clear the previous build and build
from scratch so for that we need a task inside the {gulp.js} file.
● We have created one more task build that will cover all the four tasks for JS, CSS,
images, and clean asset tasks.
{ gulp.js }
8
View Helpers
● Helpers are basically functions that can be used inside the view by passing them to
locals.
● We will create a helper function that will be based upon the development or the
production environment.
{ view_helper.js}
{index.js}
9
Summarizing Production Setup
● We set up the development environment and moved all the passwords and keys
over there.
● We set up the production environment that was the copy of the production
environment. The only difference was that all the keys were put up into the bash
profile.
● View helpers can be globally available by parsing them into the locals of the app.
10