Express intall empty express application

npm install -g express-generator

This will create a symlink in bin which points to express module in ~/.nvm/versions/v4.0.0/lib/node_modules/ ~/.nvm/bin/express is the symlink created. This is automatically sourced since .nvm/bin is in the path mentioned in .bash_profile or .bashrc dependending on the shell you use

create a empty dir to install express app

mkdir express

install a default express app

express

This will create the folder structure of the app

install express

in the express folder type

npm install

Start a Project

Create empty dir project1

mkdir project1

cd project1

type express –help

express --help

css option stylus

We will use stylus css option so when we create an app using express use

express --css stylus

package.json

package.json has all the dependencies of the project. it is similar to maven

vim package.json

install app using package.json

npm install

npm install will install app using package.json. It will include all depdencies on package.json

launch the application

npm start

localhost 3000

app starts on localhost 3000 do a curl -i (-i is the get response headers).node js and express have an inbuilt server which launches on port 3000 after npm start

curl -i localhost:3000

What does package.json do

package.json has a dependency section

npm install looks at these dependecies and installs them in node_modules. Do not checkin node_modules

stylus files

.styl files are css preprocessors which have code to generate css. node will read these files and generate css files. These files are in the public/stylesheets

routes

routes is a switch board. currently when you start app it will just have the index view

views

views are present in /views folder. It will have a index.jade which extends from layout.jade

app.js

first block is requires. the next instantiates app and next sets config option. app.use is middleware code.Note the app.use(“/”, “routes”) This says routes has the root index, which will render index.js route

JADE

Jade is a templating engine processed on server side. It has syntax built on indentation

STYLUS

stylus is a css language. It can assign variables to to constants

eg link:color = #FFFFFF. a{color: link-color} instead of repeating FFFFF all around code (similar to public static String in java)

check style.styl in project created

BOOTSTRAP

stacked to horizontal(one of the mostly used features)

we can create a row and in the row can have div with classes .col-mid-1 etc. Search stacked to horizontal in bootstrap site

Bootstrap too comes with less and saas version apart from its css version

STATIC FILES

static files are served using the public folder in the project. If I create a file named hello.html in public folder it can be accessed as http://localhost:3000/hello.html. Basically public is root for static files

TEMPLATES OTHER THAN JADE AND STYLUS

moustache

moustace is tamplating engine which uses curly braces {}. One of the main things in moustache is that it can be used with many languager

Handlebars.js

build only for javascript. it is build over moustache and provides server side and client side templating

to use handlebars put express-handlebars in package.json and install it using npm install, then change your views engine in app.js and then make sure you name views with .handlebars extension

Saas

saas is another preprocessor option built with ruby. with epxress you can use it using express --css compass

Testing

it takes control of the browser and takes control of your application as user would

it tests the entire website from css to JS to html to infrastructure to backend to database

Its end to end testing from browser to database

full stack testing is slow

protractor(javascript) and sst(python) can write code to run selenium (we can code tests to invoke selenium)

Also selenium will not make it clear where in code the problem lies. eg we might get error on UI but the problem might be network connectivity at backend or just a temp network glitch or a code error ..we dont know

Hence we write unit tests

Test tools

in package.json check devDependencies we have karma(test runner), mocha(test framework) and chai(assertion library)

We also have sinon which is mocking library

We have supertest which is a test client to test middleware and routes without starting the node app

notice the script section

we have a start script.so npm start will just help us to start the app

There is no magic it will just execute stuff in ./bin/www and will start the app

Note:Because this is my personal cheat sheet, I’m installing a few PHP modules that you may not need if you’re not running SilverStripe 4.x.x. Otherwise this is a pretty standard and secure LAMP installation.

Trying to SSH into the server from another machine you should receive this error: Permission denied (publickey)

Disable root login

As the admin user:

$ sudo passwd -l root

You will be prompted to enter the sudo user’s password.

SECURITY SECOND: Add a firewall.

$ sudo apt-get install ufw

Make sure IPv6 is enabled (you are using IPv6, correct?)

$ sudo nano /etc/default/ufw

IPV6=yes

Save and close and set up rules.

Allow connections:

$ sudo ufw allow <port>/<optional: protocol>

Examples:

$ sudo ufw allow 80/tcp or sudo ufw allow 80 or sudo ufw allow www

Deny Connections:

$ sudo ufw deny <port>/<optional: protocol>

Example:

$ sudo ufw deny 3306 (Deny default mysql port)

Start by denying all incoming and enabling all outgoing:

$ sudo ufw default deny incoming

$ sudo ufw default allow outgoing

Then allow incoming for services you need:

$ sudo ufw allow ssh

$ sudo ufw allow http

$ sudo ufw allow https

Finally, enable the firewall

$ sudo ufw enable

Common inbound ports to leave open

80 http

443 https

22 ssh

Common inbound ports to close

everything else

LAMP installation and setup (mod_php)

Install Apache

$ sudo apt-get update

$ sudo apt-get install apache2 -y

Install MariaDB

$ sudo apt-get install software-properties-common

$ sudo apt install mariadb-server mariadb-client

You might be prompted to give root a password. Just leave it blank

Run the MySQL secure installation

$ sudo mysql_secure_installation

Remember to set a root password. By default connections to MariaDB are done through unix_socket. In the next steps you will create a non-root user. For that user you can use password authentication is necessary.

Requirements

Install Apache, PHP, MySQL

All required components can be installed from the official package sources. Here you can install other server components besides Apache, MySQL and PHP.

Expert info: During the installation, a password for the database administrator root is always requested. Please choose this password carefully and keep it safe. And please do not confuse the database administrator with the system administrator account root. They are two completely different users, even if the name is identical.

PHP Installation

Apache PHP Setup

You have successfully installed your PHP versions, but we need to tell Apache to use them. You will again need to edit the /usr/local/etc/httpd/httpd.conf. Modify the paths as follows, comment out all but one entry:

PHP Switcher Script

We hard-coded Apache to use PHP 5.6, but we really want to be able to switch between versions. Luckily, some industrious individuals have already done the hard work for us and written a very handy little PHP switcher script.

Install zsh

Open terminal and paste.

brew install zsh

We need you “oh-my-zsh”

Oh-My-Zsh is an open source, community-driven framework for managing your ZSH configuration. It comes bundled with a ton of helpful functions, helpers, plugins, themes and a few things that make you shout…

“Oh My ZSH!”

Install oh-my-zsh

The oh-my-zsh will be replace default terminal with zsh automatically when you installed.

Manage Plugins

In this case I want to enable plugin ‘docker’ on my zsh, so I’ll run this command

vi ~/.zshrc

and type “/plugin” (without quotes) press enter, type ‘i’ character and insert the plugin that you want to add.

...# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/# Example format: plugins=(rails git textmate ruby lighthouse)# Add wisely, as too many plugins slow down shell startup.plugins=( git)

In this case, I’ll add docker plugin, just add “docker” to our parentheses.

...# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/# Example format: plugins=(rails git textmate ruby lighthouse)# Add wisely, as too many plugins slow down shell startup.plugins=( git docker)

After you satisfied, press ‘Esc’ and type ‘:wq’ which means you save a file and exit immediately. And restart iTerm2.

Install XCode CLI Tools

You can use a helper shell script to do this for you. The source comes from this gist. Alternatively, view its source, follow the code, and find your corresponding version of XCode CLI Tools and install accordingly.

Copy + Paste

If you don’t have a new enough version of OpenSSL, you won’t be able to download the script with wget or curl, so just open the link manually in a web browser and save the file with the same name below, on your Desktop.

2. Install Homebrew

This command will use ruby (a language included in the Xcode cli tools) to download a well maintained install script, to perform the install and setup of homebrew (and the brew command). The $(curl ...) portion performs a download of the install script and passes it to the ruby command to execute. Feel uncomfortable executing code you didn’t write? Read the install script for yourself.

Search

brew search wget

Install

brew install wget

Use

Use like normal!

wget --help

3. Setup (Tap) Homebrew Cask

brew tap caskroom/cask

This taps the caskcaskroom. This makes all cask content available for search and install.

Search

brew cask search google-chrome

Alternatively, cask availablility will return under a normal brew search command, such as brew search google-chrome.

Install

brew cask install google-chrome

Use

Use like normal! Google Chrome is now an application in your /Applications/ directory, accessible via Finder, Launchpad, etc.

Why?

Homebrew is about the easiest way to install tools for Mac. Homebrew Cask is about the easiest way to install a GUI application, which does perform a native install, it’s just tracked to be more easily upgraded.R