getting started with - nikola brežnjak · 2014-11-27 · running node.js node.js cli...

25
Getting started with Getting started with Brežnjak Nikola http://nikola-breznjak.com

Upload: others

Post on 18-Jun-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Getting started withGetting started with

Brežnjak Nikolahttp://nikola-breznjak.com

Page 2: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Yo, what's the agenda?

● What is a MEAN stack?● MongoDB● Express● AngularJS● Node.js

● Q & A

Page 3: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

I'm a old school web dev – what does that even MEAN?

Page 4: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

LAMP stack

●Linux server on which you’re running an

●Apache web server with

●MySql as a database and

●PHP as the backend language

Page 5: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Ingredients for a decent Web App

● HTML and CSS is a must● JavaScript (jQuery) is expected● PHP● SQL

Page 6: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

One language to rule them all

Page 7: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

JS devs unite

● Full-stack JavaScript developer● Frontend and backend devs now

work in conjunction using the same language across all layers

Page 8: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Y U NO interested bro!?

Page 9: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

What is MEAN, and why it’s GOOD?

● MongoDB as the database● Express as the web framework● AngularJS as the frontend

framework, and● Node.js as the server platform

Page 10: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Advantages of the MEAN stack

● Single language is used in the whole application

● Support for the MVC pattern● JSON is used for transferring data● Node.js’s huge module library● Open source

Page 11: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

We now know what is a MEAN stack, lets go home

● how to put it all together● how to install all the 4 parts of the

MEAN stack● basic usage of all 4 of them● https://hackhands.com/how-to-get-start

ed-on-the-mean-stack/has instructions for Mac OS, Windows and Linux

Page 12: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

MongoDB

● MongoDB (from "humongous")– open-source document database– JSON-style documents– leading NoSQL database

Page 13: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Installing MongoDB

● https://www.mongodb.org/downloads● download and extract the archive file

to C:\mongodb● create the folder (C:\data\db) to

store the database files● make sure port 27017 is free to use

Page 14: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Running MongoDB and using the MongoDB shell

● running directly and as a service● mongod & mongo binaries● show dbs● use db● show collections● db.todos.insert({title: "MEAN"})● db.todos.find()● http://try.mongodb.org/

Page 15: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Node.js

● Invented by Ryan Dahl in 2009● platform built on Chrome’s JavaScript

runtime called V8– compiles JavaScript code to native

machine code before executing it– event-driven– non-blocking I/O model is perfect for real-

time applications that run across distributed devices

● https://hackhands.com/delving-node-js-express-web-framework/

Page 16: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Installing Node.js

● http://nodejs.org/download/● Windows and Mac OS

– run the installer, Next, Next, Next, Finish type of installation

● Linux– configure, make, make install

Page 17: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Running Node.js

● Node.js CLI● console.log('We're MEAN');● node mean.js● NPM (node package manager)

– comes with Node.js installation– registry for public packages (100k+)– local and global installation mode– npm install <package>– npm install <package> -g

Page 18: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Simplest Web server ever

var http = require('http');

http.createServer(function (req, res) {

res.writeHead(200, {'Content-Type': 'text/plain'});

res.end('Hello World\n');

}).listen(1337, '127.0.0.1');

console.log('Server running at http://127.0.0.1:1337/');

Page 19: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Installing Express

● Web application framework for Node.js● npm init● package.json● npm install express --save

Page 20: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Simplest web server ever, part #2

var express = require('express');var app = express();

app.get('/', function (req, res) { res.send('We are MEAN!');})

var server = app.listen(1337, function () { console.log('App @ http://127.0.0.1:1337')})

Page 21: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

AngularJS

● Frontend JavaScript framework– Single-page applications– MVC architecture– built and maintained by Google

● Few of the cool features are:– two-way data binding– extended HTML w/ attributes– improved code structure– easier testing through dependency

injection

Page 22: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Downloading AngularJS

● https://angularjs.org/● <script

src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js"></script>

● We can do better with Bower– npm install bower -g– Git dependency (http://git-scm.com/

, great tutor https://try.github.io/)– bower install angular– bower_components folder– bower.json

Page 23: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Testrun AngularJS

<!doctype html><html ng-app> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js "></script> </head> <body> <div> <label>Name:</label> <input type="text" ng-model="yourName" placeholder="Enter a name here"> <hr>

<h1>Hello {{yourName}}!</h1> </div></body></html>

Page 24: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

CALL ME MAYBE?

● https://hackhands.com/hitman666/● https://hackhands.com/how-to-get-started

-on-the-mean-stack/● https://hackhands.com/delving-node-js-e

xpress-web-framework/

Page 25: Getting started with - Nikola Brežnjak · 2014-11-27 · Running Node.js Node.js CLI console.log('We're MEAN'); node mean.js NPM (node package manager) – comes with Node.js installation

Le questions???