Project Setup

node.js & npm

node.js

  • JavaScript runtime environment
  • Server Scripting with JavaScript
  • pretty widespread in nowadays, keyword: Full-Stack JS

npm

  • node package manager
  • a part of node.js (also installed together with the installer)
  • kind of the same as maven for Java

Angular CLI

Angular CLI

  • Command Line Interface for Angular Projects
  • useful commands for...
    • Creating, Building, Testing and Running Angular Projects
    • Creation of services, components, directives, etc.
    • See Angular CLI docs

Root Folder

workspace configuration files

package.json

  • comparable to a maven pom.xml
  • defines the version of the project and the dependencies
  • own scripts can be added
                    
                          "scripts": {
                              "clean": "npm run rimraf dist",
                              "build": "npm run clean && npm run ng build"
                          }
                    
                

Versioning

  • Many libraries use Semantic Versioning
  • 1.2.3: Only this exact version
  • ~1.2.3: bugfixes (1.2.X)
  • ^1.2.3: minor changes / features (1.X.Y)
  • 1.2.x: same as ~ (Bugfixes)
  • *: all versions

Semantic Versioning Cheatsheet

package-lock.json

  • breaks down and locks indirect dependencies
  • Ensures that the exact same dependencies are used when installed multiple times (CI, coworker).

Installation of Dependencies

  • With your console / terminal: npm install jquery --save-exact
  • add a row to your package.json & run npm install
                    
                        "jquery": "2.4.6",
                    
                

shorthand

  • npm install: npm i
  • --save-dev: -D
  • --save-exact: -E
  • --save-dev-exact: -D -E
                    
                        npm i -E @angular/http
                    
                

Local Repository

  • the "node_modules" folder contains the local repository with all the installed dependencies
  • Having problems? Delete the folder and rerun npm install
  • Do NOT check in node_modules to your vcs!

Global Installation

Do NOT install project dependencies globally!

  • Access to local installed packages is easily possible
  • "node_modules/.bin" is accessible in the package.json scripts section

Local Module

                    
                        "devDependencies": {
                            "webpack": "2.2.1",
                            "karma": "0.12.1"
                        },
                        "scripts": {
                            "build": "webpack",
                            "test": "npm run build && npm run karma start"
                        }
                    
                

run in terminal: "npm run build"

Other files in root folder

.npmrc

  • special configuration for baloise
  • where is our registry proxy located - our nexus
  • standard npm configuration file

src Folder

files for a specific application

src

  • See the official docs
  • src/app subfolder - where we write code, where you work on in 99% of your time

Questions are coming