{"id":20039623,"url":"https://github.com/mumer29/nodejs-summary","last_synced_at":"2026-02-04T02:04:01.638Z","repository":{"id":171238917,"uuid":"409679258","full_name":"mumer29/NodeJS-Summary","owner":"mumer29","description":null,"archived":false,"fork":false,"pushed_at":"2021-09-23T17:11:22.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-12T19:12:49.332Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mumer29.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-23T17:10:19.000Z","updated_at":"2021-09-23T17:11:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"353d35d6-0097-47ca-b612-e38c718208fa","html_url":"https://github.com/mumer29/NodeJS-Summary","commit_stats":null,"previous_names":["mumer29/nodejs-summary"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mumer29%2FNodeJS-Summary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mumer29%2FNodeJS-Summary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mumer29%2FNodeJS-Summary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mumer29%2FNodeJS-Summary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mumer29","download_url":"https://codeload.github.com/mumer29/NodeJS-Summary/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241470341,"owners_count":19968039,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T10:38:27.396Z","updated_at":"2026-02-04T02:03:56.591Z","avatar_url":"https://github.com/mumer29.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 --\u003e\n\n- [1.Intro](#1intro)\n\t- [Needs to make a web server](#needs-to-make-a-web-server)\n- [2.Modules, Export and Require](#2modules-export-and-require)\n\t- [Modules](#modules)\n\t- [Build a module](#build-a-module)\n\t\t\t- [Name value pair](#name-value-pair)\n\t\t\t- [Object](#object)\n\t\t\t- [Object Literal](#object-literal)\n\t- [Prototypal inheritance](#prototypal-inheritance)\n\t- [Function constructor](#function-constructor)\n\t- [Immediately Invoked Functions Expressions (IIFEs)](#immediately-invoked-functions-expressions-iifes)\n\t- [How Modules Work](#how-modules-work)\n\t- [Require](#require)\n\t- [Module Patterns](#module-patterns)\n\t\t\t- [Use always  `module.exports` instead of `export` although they do the same.](#use-always-moduleexports-instead-of-export-although-they-do-the-same)\n\t- [Native Modules](#native-modules)\n\t- [Modules and ES6](#modules-and-es6)\n- [3.Events And EventEmitter](#3events-and-eventemitter)\n\t- [Events](#events)\n\t\t- [Object Properties and Methods](#object-properties-and-methods)\n\t\t- [Functions and Arrays](#functions-and-arrays)\n\t- [Node Event Emitter](#node-event-emitter)\n\t\t- [Event Listener](#event-listener)\n\t\t- [Our Event Emitter](#our-event-emitter)\n\t\t- [Magic String](#magic-string)\n\t- [Prototype chain](#prototype-chain)\n\t- [Inheriting from event emitter](#inheriting-from-event-emitter)\n\t- [ES5](#es5)\n\t\t- [Template literals](#template-literals)\n\t\t- [call() and apply()](#call-and-apply)\n\t- [Inheriting pattern 2](#inheriting-pattern-2)\n\t- [ES6 Classes](#es6-classes)\n\t- [Inheriting in ES6 Classes](#inheriting-in-es6-classes)\n- [4.Synchrony](#4synchrony)\n\t\t\t- [libuv](#libuv)\n\t\t\t- [Buffer](#buffer)\n\t\t\t- [Stream](#stream)\n\t\t\t- [Binary data](#binary-data)\n\t\t\t- [Character sets](#character-sets)\n\t\t\t- [Encoding](#encoding)\n\t- [Buffers](#buffers)\n\t- [ArrayBuffer](#arraybuffer)\n\t- [Callbacks](#callbacks)\n\t- [Files](#files)\n\t\t\t- [Error First Callback](#error-first-callback)\n\t- [Streams](#streams)\n\t\t\t- [Chunk](#chunk)\n\t- [Pipes](#pipes)\n\t\t\t- [Method chaining](#method-chaining)\n- [5.HTTP](#5http)\n\t\t\t- [Protocol](#protocol)\n\t\t\t- [Port](#port)\n\t\t\t- [HTTP](#http)\n\t\t\t- [MIME Type](#mime-type)\n\t\t\t- [http_parser](#httpparser)\n\t- [HTTP server](#http-server)\n\t- [Output HTML and Templates](#output-html-and-templates)\n\t\t\t- [Template](#template)\n\t- [Streams and Performance](#streams-and-performance)\n\t\t\t- [API](#api)\n\t\t\t- [Endpoint](#endpoint)\n\t- [Outputting a JSON](#outputting-a-json)\n\t\t\t- [Serialize](#serialize)\n\t- [Routing](#routing)\n- [6.NPM](#6npm)\n\t\t\t- [Semantic Versioning](#semantic-versioning)\n\t- [Package.json](#packagejson)\n\t- [Global dependencies](#global-dependencies)\n\t\t\t- [nodemon](#nodemon)\n- [7.Express](#7express)\n\t\t\t- [Environment variables](#environment-variables)\n\t\t\t- [Http method (verbs)](#http-method-verbs)\n\t- [Routes](#routes)\n\t- [Static Files and Middleware](#static-files-and-middleware)\n\t\t\t- [Midleware](#midleware)\n\t- [Templates and Template Engines](#templates-and-template-engines)\n\t- [Querystring and Post Parameters](#querystring-and-post-parameters)\n\t\t- [Querystring](#querystring)\n\t\t- [Form Post](#form-post)\n\t\t- [Post as json](#post-as-json)\n\t- [RESTful API and JSON](#restful-api-and-json)\n\t\t\t- [REST](#rest)\n\t- [Structuring the Application](#structuring-the-application)\n\t\t- [Structuring with Express](#structuring-with-express)\n\t\t- [Our own Structure](#our-own-structure)\n- [8.MEAN](#8mean)\n\t\t\t- [DOM](#dom)\n\t- [Angular](#angular)\n\t- [Separating Server code from Client code](#separating-server-code-from-client-code)\n- [9.Build an app](#9build-an-app)\n\t- [1. Init](#1-init)\n\t- [2. Connect to the Database](#2-connect-to-the-database)\n\t- [3. Adding Data](#3-adding-data)\n\t- [4. Create the API](#4-create-the-api)\n\n\u003c!-- /TOC --\u003e\n# 1.Intro\n## Needs to make a web server\n\n* Better ways to organize our code into reusable pieces\n* Ways to deal with files\n* Ways to deal with databases\n* The ability to communicate over the Internet\n* The ability to accept requests and send responses\n* A way to deal with work that takes long time\n\n\n# 2.Modules, Export and Require\n## Modules\nReusable block of code whose existence does not accidentally impact other code\n\n**Common JS Modules**\nAn agreed upon standard for how code modules should be structured\n\n**First class Functions**\nEverything you can do with other types you can do with functions\n\n**Expression**\nA block of code that results in a value\n\n\n```javascript\n\n\t// function statement\n\tfunction greet() {\n\t\tconsole.log('hi');\n\t}\n\tgreet();\n\n\t// functions are first-class\n\tfunction logGreeting(fn) {\n\t\tfn();\n\t}\n\tlogGreeting(greet);\n\n\t// function expression\n\tvar greetMe = function() {\n\t\tconsole.log('Hi Tony!');\n\t}\n\tgreetMe();\n\n\t// it's first-class\n\tlogGreeting(greetMe);\n\n\t// use a function expression to create a function on the fly\n\tlogGreeting(function() {\n\t\tconsole.log('Hello Tony!');\n\t});\n```\n\n## Build a module\n\n**app.js**\n```javascript\n\n\tvar greet = require('./greet'); // returns what we have in `module.exports`\n\tgreet();\n```\n**greet.js**\n```javascript\n\n\tvar greet = function() {\n\t\tconsole.log('Hello!');\n\t};\n\n\tmodule.exports = greet;\n```\n#### Name value pair\nA name which maps to a value.\nThe name can be defined more than once, but only can have one value in any given **context**\n`Address = \"Sesam street\"`\n#### Object\nCollection of name/value pairs\n#### Object Literal\nName/value pairs separated by commas and surrounded by curly braces\n```javascript\n\n\tvar person = {\n\t\tname: 'Peter',\n\t\tlastname:'Doe',\n\t\tworkplace:{\n\t\t\tStreet:'Sesam street',\n\t\t\tNumber: '1'\n\t\t},\n\t\tgreet: function(){\n\t\t\t\tconsole.log('Hello ' + this.name + ' ' + this.lastname )\n\t\t}\n\t};\n\n\tperson.greet();\n\tconsole.log(person['name'])\n```\n## Prototypal inheritance\nEvery object points to a `proto{}` object\n\n## Function constructor\nA function used to build objects using `new`\n```javascript\n\n\tfunction Person(firstname, lastname) {\n\t\tthis.firstname = firstname;\n\t\tthis.lastname = lastname;\n\t}\n\n\n\tPerson.prototype.greet = function() {\n\t\tconsole.log('Hello, ' + this.firstname + ' ' + this.lastname);\n\t};\n\n\tvar john = new Person('John', 'Doe');\n\tjohn.greet();\n\n```\n\n## Immediately Invoked Functions Expressions (IIFEs)\nRun the function at the point it is created. Add a `()` after its declaration.\n```javascript\n\n\tvar firstname = 'Jane';\n\n\t(function (lastname) {\n\n\t\tvar firstname = 'John';\n\t\tconsole.log(firstname);\n\t\tconsole.log(lastname);\n\n\t}('Doe'));\n\n\tconsole.log(firstname);\n```\n\n## How Modules Work\n`require` is a function, that you pass a 'path' to\n`module.exports` is what the require function returns\nthis works because your code is actually wrapped in a function that is given these things as function parameters\n\n**app.js**\n```javascript\n\n\tvar greet = require('./greet'); // returns what we have in `module.exports`\n\tgreet();\n```\n**greet.js**\n```javascript\n\n\tvar greet = function() {\n\t\tconsole.log('Hello!');\n\t};\n\n\tmodule.exports = greet;\n```\n\n## Require\n\n**app.js**\n```javascript\n\n\tvar greet = require('./greet');\n\n\tgreet.english();\n\tgreet.spanish();\n```\n**greet/index.js**\n```javascript\n\n\tvar english = require('./english');\n\tvar spanish = require('./spanish');\n\n\tmodule.exports = {\n\t\tenglish: english,\n\t\tspanish: spanish\n\t};\n```\n**greet/english.js**\n```javascript\n\n\tvar greetings = require('./greetings.json');\n\n\tvar greet = function() {\n\t\tconsole.log(greetings.en);\n\t}\n\n\tmodule.exports = greet;\n```\n\n**greet/spanish.js**\n```javascript\n\n\tvar greetings = require('./greetings.json');\n\n\tvar greet = function() {\n\t\tconsole.log(greetings.es);\n\t}\n\n\tmodule.exports = greet;\n```\n**greet/greetings.json**\n```json\n\n\t{\n\t\t\"en\": \"Hello\",\n\t\t\"es\": \"Hola\"\n\t}\n```\n\n## Module Patterns\n\n**app.js**\n```javascript\n\n\tvar greet = require('./greet1');\n\tgreet();\n\n\tvar greet2 = require('./greet2').greet;\n\tgreet2();\n\n\tvar greet3 = require('./greet3');\n\tgreet3.greet();\n\tgreet3.greeting = 'Changed hello world!';\n\n\tvar greet3b = require('./greet3');\n\tgreet3b.greet(); // Returns 'Changed hello world!' -\u003e The result of module.export is cached so the whole greet3 is only called once\n\n\tvar Greet4 = require('./greet4');\n\tvar grtr = new Greet4();\n\tgrtr.greet();\n\n\tvar greet5 = require('./greet5').greet;\n\tgreet5();\n```\n\n**greet1.js**\n```javascript\n\n\tmodule.exports = function() {\n\t\tconsole.log('Hello world');\n\t};\n```\n\n**greet2.js**\n```javascript\n\n\tmodule.exports.greet = function() {\n\t\tconsole.log('Hello world!');\n\t};\n```\n\n**greet3.js**\n```javascript\n\n\tfunction Greetr() {\n\t\tthis.greeting = 'Hello world!!';\n\t\tthis.greet = function() {\n\t\t\tconsole.log(this.greeting);\n\t\t}\n\t}\n\n\tmodule.exports = new Greetr();\n```\n\n**greet4.js**\n```javascript\n\n\tfunction Greetr() {\n\t\tthis.greeting = 'Hello world!!!';\n\t\tthis.greet = function() {\n\t\t\tconsole.log(this.greeting);\n\t\t}\n\t}\n\n\tmodule.exports = Greetr;\n```\n\n**greet5.js**\nRevealing module pattern: Exposing only the properties and methods you want via a returned object\n```javascript\n\n\tvar greeting = 'Hello world!!!!';\n\n\tfunction greet() {\n\t\tconsole.log(greeting);\n\t}\n\n\tmodule.exports = {\n\t\tgreet: greet // Only the greet is \"exposed\" (public)\n\t}\n```\n#### Use always  `module.exports` instead of `export` although they do the same.\n\n## Native Modules\n[nodejs.org/api](nodejs.org/api)\n\n```javascript\n\n\tvar util = require('util');\n\n\tvar name = 'Tony';\n\tvar greeting = util.format('Hello, %s', name);\n\tutil.log(greeting);\n```\n## Modules and ES6\n\n**greet.js**\n```javascript\n\n\texport function greet(){\n\t\tconsole.log('Hello');\n\t}\n```\n\n**app.js**\n```javascript\n\n\timport * as greetr from 'greet';\n\tgreetr.greet();\n```\n# 3.Events And EventEmitter\n## Events\nSomething that has happened in our application that we can respond to\n\n* **System Events**: C++ core (libuv)\n* **Custom Events**: Javascript core (Event Emitter)\n\n### Object Properties and Methods\n```javascript\n\n\tvar obj = {\n\t\tgreet: 'Hello'\n\t}\n\n\tconsole.log(obj.greet);\n\tconsole.log(obj['greet']);\n\tvar prop = 'greet';\n\tconsole.log(obj[prop]);\n```\n\n### Functions and Arrays\n```javascript\n\n\tvar arr = [];\n\n\tarr.push(function() {\n\t\tconsole.log('Hello world 1');\n\t});\n\tarr.push(function() {\n\t\tconsole.log('Hello world 2');\n\t});\n\tarr.push(function() {\n\t\tconsole.log('Hello world 3');\n\t});\n\n\tarr.forEach(function(item) {\n\t\titem();\n\t});\n```\n\n## Node Event Emitter\n### Event Listener\nThe code that responds to an event\n### Our Event Emitter\n**Emitter.js**\n```javascript\n\n\tfunction Emitter() {\n\t\tthis.events = {};\n\t}\n\n\tEmitter.prototype.on = function(type, listener) {\n\t\tthis.events[type] = this.events[type] || [];\n\t\tthis.events[type].push(listener);\n\t}\n\n\tEmitter.prototype.emit = function(type) {\n\t\tif (this.events[type]) {\n\t\t\tthis.events[type].forEach(function(listener) {\n\t\t\t\tlistener();\n\t\t\t});\n\t\t}\n\t}\n\n\tmodule.exports = Emitter;\n```\n**app.js**\n```javascript\n\n\tvar Emitter = require('./emitter');\n\n\tvar emtr = new Emitter();\n\n\temtr.on('greet', function() {\n\t\tconsole.log('Somewhere, someone said hello.');\n\t});\n\n\temtr.on('greet', function() {\n\t\tconsole.log('A greeting occurred!');\n\t});\n\n\tconsole.log('Hello!');\n\temtr.emit('greet');\n```\n### Magic String\nA String that has some special meaning in our code. Bad because of typos.\nUse config files instead.\n```javascript\n\n\tmodule.exports = {\n\t\tevents: {\n\t\t\tGREET: 'greet'\n\t\t}\n\t}\n```\n\n```javascript\n\n\tvar Emitter = require('events');\n\tvar eventConfig = require('./config').events;\n\n\tvar emtr = new Emitter();\n\n\temtr.on(eventConfig.GREET, function() {\n\t\tconsole.log('Somewhere, someone said hello.');\n\t});\n\n\temtr.on(eventConfig.GREET, function() {\n\t\tconsole.log('A greeting occurred!');\n\t});\n\n\tconsole.log('Hello!');\n\temtr.emit(eventConfig.GREET);\n```\n## Prototype chain\nAnother way to create objects `Object.create(...)`\n\n```javascript\n\n\tvar person = {\n\t\tfirstname: '',\n\t\tlastname: '',\n\t\tgreet: function() {\n\t\t\treturn this.firstname + ' ' + this.lastname;\n\t\t}\n\t}\n\n\tvar john = Object.create(person);\n\tjohn.firstname = 'John';\n\tjohn.lastname = 'Doe';\n\n\tvar jane = Object.create(person);\n\tjane.firstname = 'Jane';\n\tjane.lastname = 'Doe';\n\n\tconsole.log(john.greet());\n\tconsole.log(jane.greet());\n```\n\n## Inheriting from event emitter\nSet to our object a prototype of the Emitter\nAllow us create objects with the Emitter properties\n\n```javascript\n\n\tvar EventEmitter = require('events');\n\tvar util = require('util');\n\n\tfunction Greetr() { // This is call to a \"function constructor\"\n\t\tthis.greeting = 'Hello world!';\n\t}\n\n\tutil.inherits(Greetr, EventEmitter); //\u003c--\n\n\tGreetr.prototype.greet = function(data) {\n\t\tconsole.log(this.greeting + ': ' + data);\n\t\tthis.emit('greet', data);\n\t}\n\n\tvar greeter1 = new Greetr();\n\n\tgreeter1.on('greet', function(data) {\n\t\tconsole.log('Someone greeted!: ' + data);\n\t});\n\n\tgreeter1.greet('Tony');\n```\n\n## ES5\n### Template literals\nA way to concatenate strings in ES6\n```javascript\n\n\tvar greet2 = `Hello ${ name }`;\n```\n```javascript\n\n\tvar a = 5;\n\tvar b = 10;\n\tconsole.log(`Fifteen is ${a + b} and\\nnot ${2 * a + b}.`);\n```\n### call() and apply()\n```javascript\n\n\tvar obj = {\n\t\tname: 'John Doe',\n\t\tgreet: function() {\n\t\t\tconsole.log(`Hello ${ this.name }`);\n\t\t}\n\t}\n\n\tobj.greet();\n\tobj.greet.call({ name: 'Jane Doe'}); // this will point the what is passed in call\n\tobj.greet.apply({ name: 'Jane Doe'}); // idem\n\n\t// With params we see the difference\n\tvar obj = {\n\t\tname: 'John Doe',\n\t\tgreet: function(param1,param2) {\n\t\t\tconsole.log(`Hello ${ this.name }`);\n\t\t}\n\t}\n\n\tobj.greet.call({ name: 'Jane Doe'},param1,param2);\n\tobj.greet.apply({ name: 'Jane Doe'},[param1,param2]);\n```\n## Inheriting pattern 2\nWe need the object that inherits to also have the `this`  methods and properties of the inherited object.\n```javascript\n\n\tfunction Greetr() { // This is call to a \"function constructor\"\n\t\tEventEmitter.call(this) //\u003c-- also called \"super constructor\"\n\t\tthis.greeting = 'Hello world!';\n\t}\n\n```\n\n```javascript\n\n\tvar util = require('util');\n\n\tfunction Person() {\n\t\tthis.firstname = 'John';\n\t\tthis.lastname = 'Doe';\n\t}\n\n\tPerson.prototype.greet = function() {\n\t\tconsole.log('Hello ' + this.firstname + ' ' + this.lastname);\n\t}\n\n\tfunction Policeman() {\n\t\tPerson.call(this);// Without this line `this` object wont have firstname and lastname.\n\t\tthis.badgenumber = '1234';\n\t}\n\n\tutil.inherits(Policeman, Person);\n\tvar officer = new Policeman();\n\tofficer.greet();\n```\n\n## ES6 Classes\n```javascript\n\n\t'use strict'; // like 'lint' for javascript\n\n\tclass Person {\n\t\tconstructor(firstname, lastname) {\n\t\t\tthis.firstname = firstname;\n\t\t\tthis.lastname = lastname;\n\t\t}\n\n\t\tgreet() {\n\t\t\tconsole.log('Hello, ' + this.firstname + ' ' + this.lastname);\n\t\t}\n\t}\n\n```\n## Inheriting in ES6 Classes\n\n```javascript\n\n\tvar EventEmitter = require('events');\n\n\tclass Greetr extends EventEmitter {\n\t\tconstructor() {\n\t\t\tsuper();\n\t\t\tthis.greeting = 'Hello world!';\n\t\t}\n\n\t\tgreet(data) {\n\t\t\tconsole.log(`${ this.greeting }: ${ data }`);\n\t\t\tthis.emit('greet', data);\n\t\t}\n\t}\n```\n\n# 4.Synchrony\nJavascript is synchronous\nNode.js  is asynchronous\n#### libuv\nA C library inside node that deal events occurring in the operating system\n#### Buffer\nLimited size, temporary place for data being moved from one place to another\n#### Stream\nA sequence of data made available over time\n#### Binary data\nData store in binary\n#### Character sets\nA representation of characters as numbers (Unicode, Ascii...)\n#### Encoding\nHow characters are stored in binary (UTF-8). Bits used to represent each number\n## Buffers\nNeeded because javascript was not used to deal with binary data. In ES6 it does using ArrayBuffer\n```javascript\n\n\tvar buf = new Buffer('Hello', 'utf8');\n\tconsole.log(buf); //\u003cBuffer 48 65 6c 6c 6f\u003e\n\tconsole.log(buf.toString()); //Hello\n\tconsole.log(buf.toJSON()); // { type: 'Buffer', data: [ 72, 101, 108, 108, 111 ] }\n\tconsole.log(buf[2]); //108\n\n\tbuf.write('wo');\n\tconsole.log(buf.toString()); // wollo\n```\n## ArrayBuffer\n[ArrayBuffer Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays)\n```javascript\n\n\tvar buffer = new ArrayBuffer(8);\n\tvar view = new Int32Array(buffer);\n\tview[0] = 5;\n\tview[1] = 15;\n\tconsole.log(view);\t//Int32Array { '0': 5, '1': 15 }\n```\n## Callbacks\n```javascript\n\n\tfunction greet(callback) {\n\t\tconsole.log('Hello!');\n\t\tvar data = {\n\t\t\tname: 'John Doe'\n\t\t};\n\n\t\tcallback(data);\n\t}\n\n\tgreet(function(data) {\n\t\tconsole.log('The callback was invoked!');\n\t\tconsole.log(data);\n\t});\n\n\tgreet(function(data) {\n\t\tconsole.log('A different callback was invoked!');\n\t\tconsole.log(data.name);\n\t});\n\n\t//Hello!\n\t//The callback was invoked!\n\t//{ name: 'John Doe' }\n\t//Hello!\n\t//A different callback was invoked!\n\t//John Doe\n```\n## Files\n```javascript\n\n\tvar fs = require('fs');\n\n\t//synchronous\n\tvar greet = fs.readFileSync(__dirname + '/greet.txt', 'utf8');\n\tconsole.log(greet); //#1\n\n\t//asynchronous\n\tvar greet2 = fs.readFile(__dirname + '/greet.txt', 'utf8', function(err, data) {\n\t\tconsole.log(data);//#3\n\t});\n\n\tconsole.log('Done!');//#2\n```\n#### Error First Callback\nCallbacks take en error object as their first parameter.\nThe Standard.\nnull if no error.\n\n## Streams\n#### Chunk\nA piece of data being sent through a Stream\nData is split in 'chunks' and streamed\n```javascript\n\n\tvar fs = require('fs');\n\n\tvar readable = fs.createReadStream(__dirname + '/greet.txt', { encoding: 'utf8', highWaterMark: 16 * 1024 }); // highWaterMark numebr of the buffer\n\n\tvar writable = fs.createWriteStream(__dirname + '/greetcopy.txt');\n\n\treadable.on('data', function(chunk) { // Event emitter, just listenting the event starts the buffer\n\t\tconsole.log(chunk.length);\n\t\t// console.log(chunk);\n\t\twritable.write(chunk);\n\t});\n```\n## Pipes\nConn ecting two streams by writing o one stream what is being read from another\nIn node read from Readable stream to a Writable stream\n\n``` javascript\n\n\tvar fs = require('fs');\n\tvar zlib = require('zlib');\n\n\tvar readable = fs.createReadStream(__dirname + '/greet.txt');\n\n\tvar writable = fs.createWriteStream(__dirname + '/greetcopy.txt');\n\n\tvar compressed = fs.createWriteStream(__dirname + '/greet.txt.gz');\n\n\tvar gzip = zlib.createGzip();\n\n\treadable.pipe(writable); // Same as forehead sample\n\n\treadable.pipe(gzip).pipe(compressed); // Chain pipes\n```\n#### Method chaining\nA Method returns  an object so we can keep calling more methods.\nWhen it returns the parent object is called \"cascading\".\n\n# 5.HTTP\n#### Protocol\nA set of rules two sides agree on the use communicating.\nIP : Internet Protocol. Addresses\nTCP: Transmission Control Protocol. Send Packets\n#### Port\nWhich program in a computer handles a packet received.\n#### HTTP\nA set of rules and format for data being transferred on the web\n'Hypertext Transfer Protocol' (how the messages are written)\n#### MIME Type\nA standard for specifying the type of the data being sent\n'Multipurpose Internet Mail Extensions'\nExamples: application/json, text/html, image/jpeg\n\n#### http_parser\nC program that parse http requests and responses\n\n## HTTP server\n\n```javascript\n\n\tvar http = require('http');\n\n\thttp.createServer(function (req, res) {\n\n\t  res.writeHead(200, {'Content-Type': 'text/plain'});\n\t  res.end('Hello World\\n');\n\n\t}).listen(1337, '127.0.0.1');\n\n```\n## Output HTML and Templates\n```javascript\n\n\tvar http = require('http');\n\tvar fs = require('fs');\n\n\thttp.createServer(function(req, res) {\n\n\t    res.writeHead(200, { 'Content-Type': 'text/html' });\n\t    var html = fs.readFileSync(__dirname + '/index.htm', 'utf8');\n\t    var message = 'Hello world...';\n\t    html = html.replace('{Message}', message);\n\t    res.end(html);\n\n\t}).listen(1337, '127.0.0.1');\n```\n#### Template\nText designed to be the basis for final text or content after being processed\n## Streams and Performance\nWe can send chunks of data instead all at once using Streams and piping it to the response.\nUse it always.\n```javascript\n\n\tvar http = require('http');\n\tvar fs = require('fs');\n\n\thttp.createServer(function(req, res) {\n\n\t    res.writeHead(200, { 'Content-Type': 'text/html' });\n\t    fs.createReadStream(__dirname + '/index.htm').pipe(res);\n\n\t}).listen(1337, '127.0.0.1');\n```\n\n#### API\nApplication Programing Interface.\nIn node's field URLs which accept and send only data via HTTP and TCP/IP\n\n#### Endpoint\nOne URL in a web API\n\n## Outputting a JSON\n```javascript\n\n\tvar http = require('http');\n\tvar fs = require('fs');\n\n\thttp.createServer(function(req, res) {\n\n\t    res.writeHead(200, { 'Content-Type': 'application/json' });\n\t    var obj = {\n\t        firstname: 'John',\n\t        lastname: 'Doe'\n\t    };\n\t    res.end(JSON.stringify(obj));\n\n\t}).listen(1337, '127.0.0.1');\n```\n#### Serialize\nTranslating and object into a format that can be stored or transferred.\nJSON, CSV, XML are popular.\n'Deserialize' is the opposite (converting the format back into an object)\n\n## Routing\nMapping HTTP requests to content.\nGet data in the server from parameters in the http call.\n\n```javascript\n\n\tvar http = require('http');\n\tvar fs = require('fs');\n\n\thttp.createServer(function(req, res) {\n\n\t    if (req.url === '/') {\n\t        fs.createReadStream(__dirname + '/index.htm').pipe(res);\n\t    }\n\n\t    else if (req.url === '/api') {\n\t        res.writeHead(200, { 'Content-Type': 'application/json' });\n\t        var obj = {\n\t            firstname: 'John',\n\t            lastname: 'Doe'\n\t        };\n\t        res.end(JSON.stringify(obj));\n\t    }\n\t    else {\n\t        res.writeHead(404);\n\t        res.end();\n\t    }\n\n\t}).listen(1337, '127.0.0.1');\n```\n# 6.NPM\n#### Semantic Versioning\nMAYOR.MINOR.PATCH\n## Package.json\n`npm init`\n`npm install moment --save` The `--save` writes a reference in package.json\n\n```javascript\n\n\t\"dependencies\": {\n\t\t\"moment\": \"^2.13.0\" // ^ automatically updates minors ~ updates only patches\n\t}\n```\n\n\n`npm install` : Once we have the package.json we dont need to copy the modules in a new environment, just calling `npm install` will download everything for us\n\n`require` will look directly in the `node_modules` folder\n\n```javascript\n\n\tvar moment = require('moment');\n\tconsole.log(moment().format(\"ddd, hA\"));\n```\n## Global dependencies\nInstall dependencies that we only need while developing\n`npm install jasmine-node --save-dev`\nInstall globally, if we kwow we will us a package in many apps in our computer\n`npm install nodemon -g`\nThey are stored at `/usr/local/lib/node_modules/npm/node_modules`\n\n#### nodemon\nIt watches changes in the folder\n\n# 7.Express\n```javascript\n\n\tvar express = require('express');\n\tvar app = express();\n\n\tvar port = process.env.PORT || 3000;\n\n\tapp.get('/', function(req, res) {\n\t\tres.send('\u003chtml\u003e\u003chead\u003e\u003c/head\u003e\u003cbody\u003e\u003ch1\u003eHello world!\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e');\n\t});\n\n\tapp.get('/api', function(req, res) {\n\t\tres.json({ firstname: 'John', lastname: 'Doe' });\n\t});\n\n\tapp.listen(port);\n```\n#### Environment variables\nGlobal variables specific to the environment (server) our code is living in.\n#### Http method (verbs)\nSpecific type of action the request wishes to make.\nGET, POST, DELETE...\n## Routes\n```javascript\n\n\tapp.get('/person/:id', function(req, res) {\n\t\tres.send('\u003chtml\u003e\u003chead\u003e\u003c/head\u003e\u003cbody\u003e\u003ch1\u003ePerson: ' + req.params.id + '\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e');\n\t});\n```\n\n## Static Files and Middleware\n#### Midleware\nCode that sit between 2 layers of software.\nIn Express:  sitting between request and response\n```javascript\n\n\tapp.use('/assets', express.static(__dirname + '/public'));\n\n\tapp.use('/', function (req, res, next) {\n\t\tconsole.log('Request Url:' + req.url);\n\t\tnext(); // call the next Middleware\n\t});\n\tapp.get('/', function(req, res) {\n\t\tres.send('\u003chtml\u003e\u003chead\u003e\u003clink href=assets/style.css type=text/css rel=stylesheet /\u003e\u003c/head\u003e\u003cbody\u003e\u003ch1\u003eHello world!\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e');\n\t});\n```\n## Templates and Template Engines\n```javascript\n\n\t...\n\n\tapp.set('view engine', 'ejs');\n\n\tapp.get('/', function(req, res) {\n\t\tres.render('index');\n\t});\n\n\tapp.get('/person/:id', function(req, res) {\n\t\tres.render('person', { ID: req.params.id });\n\t});\n\t...\n\n```\n```html\n\n\t\u003chtml\u003e\n\t\t\u003chead\u003e\n\t\t\t\u003clink href=\"/assets/style.css\" type=\"text/css\" rel=\"stylesheet\" /\u003e // important the / before the path of the css\n\t\t\u003c/head\u003e\n\t\t\u003cbody\u003e\n\t\t\t\u003ch1\u003ePerson: \u003c%= ID %\u003e\u003c/h1\u003e\n\t\t\u003c/body\u003e\n\t\u003c/html\u003e\n```\n\n## Querystring and Post Parameters\n### Querystring\n```javascript\n\n\tGET /?id=4\u0026page=3 HTTP/1.1\n\tHost:www.learnweb.net\n\tCookie:username=abc:name:Tony\n```\n```javascript\n\n\tapp.get('/person/:id', function(req, res) {\n\t\tres.render('person', { ID: req.params.id, Qstr: req.query.qstr }); //req.query get the querystring\n\t});\n```\n### Form Post\nData in the body as objects\nUse body-parser\n\n```javascript\n\n\tPOST HTTP/1.1\n\tHost:www.learnweb.net\n\tContent-Type:application/x-www-form-urlencoded\n\tCookie:num=4;page=3\n\tusername=Tony\u0026password=pwd\n```\n\n```javascript\n\n\tvar bodyParser = require('body-parser');\n\tvar urlencodedParser = bodyParser.urlencoded({ extended: false });\n\n\tapp.post('/person', urlencodedParser, function(req, res) {\n\t\tres.send('Thank you!');\n\t\tconsole.log(req.body.firstname);\n\t\tconsole.log(req.body.lastname);\n\t});\n```\n```html\n\n\t\u003cform method=\"POST\" action=\"/person\"\u003e\n\t\tFirst name: \u003cinput type=\"text\" id=\"firstname\" name=\"firstname\" /\u003e\u003cbr /\u003e\n\t\tLast name: \u003cinput type=\"text\" id=\"lastname\" name=\"lastname\" /\u003e\u003cbr /\u003e\n\t\t\u003cinput type=\"submit\" value=\"Submit\" /\u003e\n\t\u003c/form\u003e\n```\n### Post as json\nData in the body as json\n```javascript\n\n\tPOST HTTP/1.1\n\tHost:www.learnweb.net\n\tContent-Type:application/json\n\tCookie:num=4;page=3\n\t{\n\t\t'username'='Tony',\n\t\t'password'='pwd'\n\t}\n```\n\n```javascript\n\n\tvar jsonParser = bodyParser.json();\n\n\tapp.post('/personjson', jsonParser, function(req, res) {\n\t\tres.send('Thank you for the JSON data!');\n\t\tconsole.log(req.body.firstname);\n\t\tconsole.log(req.body.lastname);\n\t});\n```\n\n```html\n\n\t\u003cscript\u003e\n\t\t$.ajax({\n\t\t\ttype: \"POST\",\n\t\t\turl: \"/personjson\",\n\t\t\tdata: JSON.stringify({ firstname: 'Jane', lastname: 'Doe' }),\n\t\t\tdataType: 'json',\n\t\t\tcontentType: 'application/json'\n\t\t});\n\t\u003c/script\u003e\n```\n## RESTful API and JSON\n#### REST\nRepresentational State Transfer. Which HTTP verbs and URLs do what.\n\n```javascript\n\n\tapp.get('/api/person/:id', function(req, res) {\n\t\t// get that data from database\n\t\tres.json({ firstname: 'John', lastname: 'Doe' });\n\t});\n\n\tapp.post('/api/person', jsonParser, function(req, res) {\n\t\t// save to the database\n\t});\n\n\tapp.delete('/api/person/:id', function(req, res) {\n\t\t// delete from the database\n\t});\n```\n\n## Structuring the Application\n### Structuring with Express\n`install express-generator -g` // do it global\n`express \u003cmy app name\u003e`// Create the architecture\n`cd \u003cmy app name\u003e` // go to the app\n`npm install` // install the packages\n\n### Our own Structure\nUsing controllers\n\n**app.js**\n```javascript\n\n\tvar express = require('express');\n\tvar app = express();\n\n\tvar apiController = require('./controllers/apiController');\n\tvar htmlController = require('./controllers/htmlController');\n\n\tvar port = process.env.PORT || 3000;\n\n\tapp.use('/assets', express.static(__dirname + '/public'));\n\n\tapp.set('view engine', 'ejs');\n\n\tapp.use('/', function (req, res, next) {\n\t\tconsole.log('Request Url:' + req.url);\n\t\tnext();\n\t});\n\n\thtmlController(app);\n\tapiController(app);\n\n\tapp.listen(port);\n```\n**htmlController**\n```javascript\n\n\tvar bodyParser = require('body-parser');\n\n\tvar urlencodedParser = bodyParser.urlencoded({ extended: false });\n\n\tmodule.exports = function(app) {\n\n\t\tapp.get('/', function(req, res) {\n\t\t\tres.render('index');\n\t\t});\n\n\t\tapp.get('/person/:id', function(req, res) {\n\t\t\tres.render('person', { ID: req.params.id, Qstr: req.query.qstr });\n\t\t});\n\n\t\tapp.post('/person', urlencodedParser, function(req, res) {\n\t\t\tres.send('Thank you!');\n\t\t\tconsole.log(req.body.firstname);\n\t\t\tconsole.log(req.body.lastname);\n\t\t});\n\t}\n```\n\n**apiController**\n```javascript\n\n\tmodule.exports = function(app) {\n\n\t\tapp.get('/api/person/:id', function(req, res) {\n\t\t// get that data from database\n\t\t\tres.json({ firstname: 'John', lastname: 'Doe' });\n\t\t});\n\n\t\tapp.post('/api/person', function(req, res) {\n\t\t\t// save to the database\n\t\t});\n\n\t\tapp.delete('/api/person/:id', function(req, res) {\n\t\t\t// delete from the database\n\t\t});\n\t}\n```\n# 8.MEAN\n#### DOM\nDocument Object Model\nThe structure browsers use to store and manage web pages\nBrowsers give JavaScript the ability to manipulate the DOM\n## Angular\n\n**app.js**\n```javascript\n\n\tvar express = require('express');\n\tvar app = express();\n\n\tvar port = process.env.PORT || 3000;\n\n\tapp.set('view engine', 'ejs');\n\tapp.use('/assets', express.static(__dirname + '/public'));\n\n\tapp.get('/', function(req, res) {\n\n\t\tres.render('index');\n\n\t});\n\n\tapp.listen(port);\n```\n**view/index.ejs**\n```html\n\n\t\u003chtml ng-app=\"TestApp\"\u003e\n\t\t\u003chead\u003e\n\t\t\t\u003ctitle\u003eThe MEAN stack\u003c/title\u003e\n\t    \t\u003cscript src=\"https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.js\"\u003e\u003c/script\u003e\n\t\t\u003c/head\u003e\n\t\t\u003cbody ng-controller=\"MainController as vm\"\u003e\n\n\t\t\t\u003cinput type=\"text\" ng-model=\"vm.message\" /\u003e\n\t\t\t\u003cbr /\u003e\n\t\t\t{{ vm.message }}\n\t\t\t\u003cbr /\u003e\n\t\t\t\u003cul\u003e\n\t\t\t\t\u003cli ng-repeat=\"person in vm.people\"\u003e\n\t\t\t\t\t{{ person.name }}\n\t\t\t\t\u003c/li\u003e\n\t\t\t\u003c/ul\u003e\n\n\t\t\t\u003cscript src=\"assets/js/app.js\"\u003e\u003c/script\u003e\n\t\t\u003c/body\u003e\n\t\u003c/html\u003e\n```\n**public/js/app.js**\n```javascript\n\n\tangular.module('TestApp', []);\n\n\tangular.module('TestApp')\n\t\t.controller('MainController', ctrlFunc);\n\n\tfunction ctrlFunc() {\n\t\tthis.message = \"Hello\";\n\n\t\tthis.people = [\n\t\t\t{\n\t\t\t\tname: 'John Doe'\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'Jane Doe'\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'Jim Doe'\n\t\t\t}\n\t\t]\n\t}\n```\n## Separating Server code from Client code\nWe can set in the server what we show in client\n**app.js**\n```javascript\n\n\tvar express = require('express');\n\tvar app = express();\n\n\tvar port = process.env.PORT || 3000;\n\n\tvar people = [\n\t\t{\n\t\t\tname: 'John Doe'\n\t\t},\n\t\t{\n\t\t\tname: 'Jane Doe'\n\t\t},\n\t\t{\n\t\t\tname: 'Jim Doe'\n\t\t}\n\t];\n\n\tapp.set('view engine', 'ejs');\n\tapp.use('/assets', express.static(__dirname + '/public'));\n\n\tapp.get('/', function(req, res) {\n\n\t\tres.render('index', { serverPeople: people }); //\u003c--\n\n\t});\n\n\tapp.listen(port);\n```\n**view/index.ejs**\n```html\n\n\t\u003chtml ng-app=\"TestApp\"\u003e\n\t\t\u003chead\u003e\n\t\t\t\u003ctitle\u003eThe MEAN stack\u003c/title\u003e\n\t\t\t\u003cscript src=\"https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js\"\u003e\u003c/script\u003e\n\t\t\u003c/head\u003e\n\t\t\u003cbody ng-controller=\"MainController as vm\"\u003e\n\t\t\t\u003cul\u003e\n\t\t\t\t\u003cli ng-repeat=\"person in vm.people\"\u003e\n\t\t\t\t\t{{ person.name }}\n\t\t\t\t\u003c/li\u003e\n\t\t\t\u003c/ul\u003e\n\t\t\t\u003cscript\u003e\n\t\t\t\tvar clientPeople = \u003c%- JSON.stringify(serverPeople) %\u003e; //\u003c--\n\t\t\t\u003c/script\u003e\n\t\t\t\u003cscript src=\"/assets/js/app.js\"\u003e\u003c/script\u003e\n\t\t\u003c/body\u003e\n\t\u003c/html\u003e\n```\n**public/js/app.js**\n```javascript\n\n\tangular.module('TestApp', []);\n\n\tangular.module('TestApp')\n\t\t.controller('MainController', ctrlFunc);\n\n\tfunction ctrlFunc() {\n\t\tthis.people = clientPeople;\n\t}\n```\n# 9.Build an app\n## 1. Init\n*1 `npm init`\n*2 `npm install express --save-dev`\n*3 `npm install ejs --save-dev`\n*4 `npm install body-parser --save-dev`\n*5 `npm install mongoose --save-dev`\n\n**app.js**\n```javascript\n\n\tvar express = require('express');\n\tvar app = express();\n\n\tvar port = process.env.PORT || 3000;\n\n\tapp.use('/assets', express.static(__dirname + '/public'));\n\n\tapp.set('view engine', 'ejs');\n\n\tapp.listen(port);\n```\n## 2. Connect to the Database\nmLab.com\n**config/config.json**\n```javascript\n\n\t{\n\t\t\"uname\":\"test\",\n\t\t\"pwd\":\"test\"\n\t}\n```\n**config/index.js**\n```javascript\n\n\tvar configValues = require('./config');\n\n\tmodule.exports = {\n\t    getDbConnectionString: function() {\n\t        return `mongodb://${configValues.uname}:${configValues.pwd}@ds013212.mlab.com:13212/nodetodo`;\n\t    }\n\t}\n```\n**models/todoModel.js**\n```javascript\n\n\tvar mongoose = require('mongoose');\n\n\tvar Schema = mongoose.Schema;\n\n\tvar todoSchema = new Schema({\n\t    username: String,\n\t    todo: String,\n\t    isDone: Boolean,\n\t    hasAttachment: Boolean\n\t});\n\n\tvar Todos = mongoose.model('Todos', todoSchema);\n\n\tmodule.exports = Todos;\n```\n\n**app.js**\n```javascript\n\n\tvar express = require('express');\n\tvar app = express();\n\tvar mongoose = require('mongoose');\n\tvar config = require('./config');\n\n\tvar port = process.env.PORT || 3000;\n\n\tapp.use('/assets', express.static(__dirname + '/public'));\n\n\tapp.set('view engine', 'ejs');\n\n\tmongoose.connect(config.getDbConnectionString());\n\n\tapp.listen(port);\n```\n## 3. Adding Data\n\n**controllers/setupController.js**\n```javascript\n\n\tvar Todos = require('../models/todoModel');\n\n\tmodule.exports = function(app) {\n\n\t   app.get('/api/setupTodos', function(req, res) {\n\n\t       // seed database\n\t       var starterTodos = [\n\t           {\n\t               username: 'test',\n\t               todo: 'Buy milk',\n\t               isDone: false,\n\t               hasAttachment: false\n\t           },\n\t           {\n\t               username: 'test',\n\t               todo: 'Feed dog',\n\t               isDone: false,\n\t               hasAttachment: false\n\t           },\n\t           {\n\t               username: 'test',\n\t               todo: 'Learn Node',\n\t               isDone: false,\n\t               hasAttachment: false\n\t           }\n\t       ];\n\t       Todos.create(starterTodos, function(err, results) {\n\t           res.send(results);\n\t       });\n\t   });\n\n\t}\n```\n**app.js**\n```javascript\n\n\tvar express = require('express');\n\tvar app = express();\n\tvar mongoose = require('mongoose');\n\tvar config = require('./config');\n\tvar setupController = require('./controllers/setupController');\n\n\tvar port = process.env.PORT || 3000;\n\n\tapp.use('/assets', express.static(__dirname + '/public'));\n\n\tapp.set('view engine', 'ejs');\n\n\tmongoose.connect(config.getDbConnectionString());\n\tsetupController(app);\n\n\tapp.listen(port);\n```\nRun\n`http://localhost:3000/api/setupTodos`\n\n## 4. Create the API\n**controllers/apiController**\n```javascript\n\n\tvar Todos = require('../models/todoModel');\n\tvar bodyParser = require('body-parser');\n\n\tmodule.exports = function(app) {\n\n\t    app.use(bodyParser.json()); // Middleware\n\t    app.use(bodyParser.urlencoded({ extended: true })); // Middleware\n\n\t    app.get('/api/todos/:uname', function(req, res) {\n\n\t        Todos.find({ username: req.params.uname }, function(err, todos) {\n\t            if (err) throw err;\n\n\t            res.send(todos);\n\t        });\n\n\t    });\n\n\t    app.get('/api/todo/:id', function(req, res) {\n\n\t       Todos.findById({ _id: req.params.id }, function(err, todo) {\n\t           if (err) throw err;\n\n\t           res.send(todo);\n\t       });\n\n\t    });\n\n\t    app.post('/api/todo', function(req, res) {\n\n\t        if (req.body.id) { // if i received an id I know that is an update\n\t            Todos.findByIdAndUpdate(req.body.id, { todo: req.body.todo, isDone: req.body.isDone, hasAttachment: req.body.hasAttachment }, function(err, todo) {\n\t                if (err) throw err;\n\n\t                res.send('Success');\n\t            });\n\t        }\n\n\t        else {\n\n\t           var newTodo = Todos({\n\t               username: 'test',\n\t               todo: req.body.todo,\n\t               isDone: req.body.isDone,\n\t               hasAttachment: req.body.hasAttachment\n\t           });\n\t           newTodo.save(function(err) {\n\t               if (err) throw err;\n\t               res.send('Success');\n\t           });\n\n\t        }\n\n\t    });\n\n\t    app.delete('/api/todo', function(req, res) {\n\n\t        Todos.findByIdAndRemove(req.body.id, function(err) {\n\t            if (err) throw err;\n\t            res.send('Success');\n\t        })\n\n\t    });\n\n\t}\n```\n**app.js**\n```javascript\n\n\tvar express = require('express');\n\tvar app = express();\n\tvar mongoose = require('mongoose');\n\tvar config = require('./config');\n\tvar setupController = require('./controllers/setupController');\n\tvar apiController = require('./controllers/apiController');\n\n\tvar port = process.env.PORT || 3000;\n\n\tapp.use('/assets', express.static(__dirname + '/public'));\n\n\tapp.set('view engine', 'ejs');\n\n\tmongoose.connect(config.getDbConnectionString());\n\tsetupController(app);\n\tapiController(app);\n\n\tapp.listen(port);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmumer29%2Fnodejs-summary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmumer29%2Fnodejs-summary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmumer29%2Fnodejs-summary/lists"}