nodejs for .net web developers

40
Ugo Lattanzi NodeJs for .NET Web developers and Viceversa: Meet the Dark Side of development Head of Technologies at Gaia (http://gaia.is.it) @imperugo [email protected] http://tostring.it MILAN november 28 th /29 th 2014 - @imperugo

Upload: codemotion

Post on 05-Jul-2015

499 views

Category:

Technology


15 download

DESCRIPTION

by Ugo Lattanzi - Vuoi passare al lato oscuro? Questa è la sessione che fa per te. Un side by side tra il mondo .NET e quello NodeJs in modo da apprenderne vantaggi, differenze, frameworks da utilizzare. Il tutto orientato al web.

TRANSCRIPT

Page 1: NodeJS for .NET web developers

Ugo Lattanzi

NodeJs for .NET Web developers and Viceversa:

Meet the Dark Side of development

Head of Technologies at Gaia (http://gaia.is.it)@[email protected] http://tostring.it

MILAN november 28th/29th 2014 - @imperugo

Page 2: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

What is node?

Node.js® is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-

driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across

distributed devices.

Page 3: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

What can I do with Node?

Http, Networking, Websocket but also an helpful tool for developers

Page 4: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

Why is so cool?is javascript

is fast

optimised (low resources)

runs everywhere

Page 5: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

…but is also for nerd!

Page 6: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

everybody love it …

Ted Dziuba defined “Node Js a cancer”

http://teddziuba.com/2011/10/node-js-is-cancer.html

(post removed)

Page 7: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

Node vs .NETIIS => Node.exe

C# / VB => Javascript

NuGet => npm

ASP.NET WebForm => Express + EJS

ASP.NET MVC => Express + Vash

ASP.NET WebAPI => Express

SignalR => Socket.io

Page 8: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

Visual Studio addicted?

don’t worry, there is a free and open source plugin (NTVS) that turns Visual Studio into a Node.js IDE

http://nodejstools.codeplex.com/

NTVS supports Editing, Intellisense, Profiling, npm, TypeScript, Debugging locally and remotely (Windows/MacOS/Linux), as well Azure

Web Sites and Cloud Service.

Page 9: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

Async

Page 10: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

Async

http://www.toptal.com/nodejs/why-the-hell-would-i-use-node-js

Page 11: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

Async

http://www.toptal.com/nodejs/why-the-hell-would-i-use-node-js

Page 12: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

Async

Page 13: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

Let’s start

Page 14: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

npm init

npm install express —save

npm install vash —save

express.js

Page 15: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

package.json is the same thing of packages.config in nuget and npm install restore the missing packages

express.js

Page 16: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

express.js

Page 17: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

express.js

Page 18: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

express.js / aspnetControllers

Model

Views

public ??

Page 19: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

express.js

Page 20: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

vash (@razor)

Vash is a template engine that offers a swift flow between code and content using Razor Syntax

it supports master pages, partial, helpers and so on

it isn’t a porting of Razor View Engine but is very similar

the file extension for the views is .vash

Page 21: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

vash (@razor)

Page 22: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

vash (@razor)

partials are simple html files into the view folder

to include a partial into your view is enough to use

@html.include(‘name_of_the_partial’)

Page 23: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

vash (@razor)

Page 24: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

How to manage 404 and 500?

add your view to the end of routing :-)

express.js

Page 25: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

express.js

Page 26: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

It’s very similar to render view but without the render command :)

express.js (API)

Page 27: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

express.js (API)

Page 28: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

there aren’t data annotation so the validation is “impractical” than .net

express-validator is a cool middleware for Express.Js that helps you to validate input data

npm install express-validator —save

express.js (validation)

Page 29: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

express.js (validation)

Page 30: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

express middleware

npm install body-parser —save

npm install compression —save

npm install cookie-parser —save

npm install express-mailer —save

npm install express-session —save

Page 31: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

database

of course you can use MS Sql Server (npm install mssql —save)

but

MongoDb “could be better” with Node (npm install mongoldb —save)

Page 32: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

database

Page 33: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

database

Page 34: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

edge.js

An edge connects two nodes. This edge connects Node.js and .NET. V8 and CLR/Mono - in process. On Windows, MacOS, and Linux.

Page 35: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

edge.js

Page 36: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

edge.js

Page 37: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

Node vs .NET

C# => NodeJs

F# => NodeJs

Python => NodeJs

TSQL => NodeJs

Powershell => NodeJs

Page 38: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

slide and demo

http://tostring.it (next days)

Page 39: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi

Q/A

Page 40: NodeJS for .NET web developers

MILAN november 28th/29th 2014 – Ugo Lattanzi