* Visit expressjs.com -- The minimalist web framework for Node.js
mkdir mean_tutorial
cd mean_tutorial
npm init
>> provide parameters
>> The configuration file "package.json" is created, thins mentions the startup file 

>>As the "Getting Started" page asks add teh following lines to your 



Details / Task
Remarks
MEAN - MySQL-Express-Angular-NodeJS --> It's scope is a subset of FullStack development

REF: build_part1_db_connection.zip
(E:\MyDevelopments\node_express\mean_tutorial\build_bkup)
Training Video Part-1
Followed youtube video (MEANSTACK Tutorial from David Acosta)
Private list of node packages as of 2019 and text list as of 2017

Express is a minimalist web framework for NodeJS

* To get started with Express visit: "https://expressjs.com"
* npm documentation: "https://docs.npmjs.com/misc/scripts#default-values"
* Search Node packages: npmjs.com (Check previous block for a list)

An Example: "https://levelup.gitconnected.com/anonymous-web-scrapping-with-node-js-tor-apify-and-cheerio-3b36ec6a45dc"
Create a folder and invoke "npm init" within that folder to initialize the folder as nodejs app.

mkdir myapp
cd myapp
npm init
Have a look at the generated file "package.json"
The "main" specifies the entry point js file
The "scripts"."start" specify the script for start command
  which defaults to "node server.js", if a file named "server.js" exists in the application folder.
We can specify our own script if needed.
Collect helloworld sample from "express.js" and put in server.js to create an express application.
Ex: Import "express:
var express_app = require('express');

Then when we run npm start server.js it fails with message " Error: Can not find module 'express'  "
Install 'express' from project folder using the below command

"npm install express --no-save" does not make an "dependencies"entry in package.json
"npm install express" or "npm install express --save" makes an "dependencies"entry for "express" with version in package.json

npm install express --save
  • This installs the express framework for our application.
  • To uninstall "express" you can run "npm uninstall express" from project home and this will uninstall and make the sub folder "node_modules" empty.
  • To find the installed version of "express" run "npm list express"
  • After each package installation the package.json is updated with the imported package under "dependency" block.
  • "package-lock.json" is generated to list all the dependencies along with version numbers to cater for all future updates to various modules. So this file must not be disturbed.
Now modify "server.js" to reflect our requirements.
Start the server using the below command
npm start server.js
Every time we make changes to server.js we need to stop the server using CTRL+C and start again using "npm start server.js"
Install "nodemon" globally
npm install -g nodemon
To avoid frequent manual restart and to enable auto restart we need to install "nodemon" globally and need to start the server using "nodemon".
Start the server using "nodemon" instead of "npm start"

nodemon server.js

"Morgan" middleware module can be used for http request logging for analysis.
var my_morgan = require('morgan');
express_app.use(my_morgan('dev')); //This prints http request details on console for every request
Use "mangoose" package to connect to mongodb from nodejs

In mongose.connect() a error handling anonymous functionmay be supplied as second optional parameter


End of Video (index=2) for "Setting up server with NodeJS, ExpressJS & MongoDB w/ mongoose"
var my_mongoose = require('mongoose');
my_mongoose.connect('mongodb://localhost:27017/tutorials', function(err){
    if(err){
        console.log('Not conencted to database. ERROR: '+err);
    } else {
        console.log('Successfully connected to database');
    }
});




PART-2 User Model and Routes

REF: build_part2_user_model_routes_dbsave_pwd_encrypt.zip
(E:\MyDevelopments\node_express\mean_tutorial\build_bkup)

Training Video Part-2
* "server.js" enhanced to define app.post()
* imported express middlewares express.json to enable parsing of the req.body json input
* Defined a user model schema using mongoose.schema havign 3 attribues username, password and email.
* In the user model declared property setters like requried, lowercase, unique etc for the attributes where as necessary to enable auto validation by the node system, without explicit validation by us.
* Defined a schema.pre('save',...) trigger for the userSchema where we called bcrypt.hash to encrypt the password before saving.
* Added the user model to module.exports so that the model could be accessed from the main applicaiotn "server.js"
* In user.save() and bcrypt.hash() we have provided callback inline functions to handle error conditions.















YOUTUBE VIDEO TUTORIALS ON MEAN STACK (Mongo-ExtJS-Angular-NodaJS)

"index=n" - is the only changing parameter in following urls:

MEAN Stack App by David Acosta

INDEX = 1 to 22 as mentioned below (in the url
  1. MEAN Stack App Introduction
  2. Setting up Server with NodeJS & ExpressJS and MongoDB w/Mongoose
  3. User Model & Routes
  4. Static Layout (Index) Using ExpressJS
  5. Mapping Bootstrap and Angular Libraries
  6. Angular Routes (ngRoute)
  7. User Registration Page, AngularJS Factory/Services, and ngAnimate
  8. User Login, AngularJS Factory/Service, Authenticate Service
  9. Keep User Logged In Using JSON Web Tokens
  10. Login with Facebook using PassportJS
  11. Login with Twitter & Google+ using PassportJS
  12. Restricting Routes (ngRoute/AngularJS)
  13. Back-End Validation w/Mongoose & Regular Expressions (RegEx)
  14. Front-End Form Validation w/AngularJS
  15. Confirm/Match Password w/AngularJS
  16. Confirmation E-mail (Nodemailer & Sendgrid)
  17. Reset Password/Forgot Username
  18. Bootstrap Modals and Expired Sessions
  19. User Permissions & Roles (CRUD - Create Read Update Delete)
  20. Search Engine (AngularJS)
  21. Deploy App Using Heroku
  22. From Heroku to Domain (Using godaddy.com)