├── .gitignore
├── .settings
└── launch.json
├── ExpressMvp.sln
├── ExpressMvp
├── .ntvs_analysis.dat
├── ExpressMvp.njsproj
├── README.md
├── app.js
├── bin
│ └── www
├── package.json
├── public
│ └── stylesheets
│ │ ├── style.css
│ │ └── style.styl
├── routes
│ ├── index.js
│ └── users.js
├── src
│ └── users.js
└── views
│ ├── error.jade
│ ├── index.jade
│ ├── layout.jade
│ └── user.jade
├── LICENSE
├── README.md
├── demo-modules
├── app.json
├── config-example.js
├── config.js
├── module-usage.js
├── sql.js
├── temperature-example.js
└── temperature.js
├── demo1
└── index.js
├── demo2
└── index.js
├── demo3
├── hello.js
└── index.js
├── demo4
├── hello.js
└── index.js
├── demo5
└── index.js
├── edge-demos
├── 101-hello-world.js
├── 102-hello-file.js
├── 103-data-marshalling.js
├── 104-hello-sql.js
├── 105-hello-assembly.js
├── data-marshalling.cs
├── file-demo.cs
└── sql-demo.cs
├── express-demo
├── ExpressApp1
│ ├── .ntvs_analysis.dat
│ ├── ExpressApp1.njsproj
│ ├── ExpressApp1.sln
│ ├── ExpressApp1.v12.suo
│ ├── README.md
│ ├── app.js
│ ├── package.json
│ ├── public
│ │ ├── fonts
│ │ │ ├── glyphicons-halflings-regular.eot
│ │ │ ├── glyphicons-halflings-regular.svg
│ │ │ ├── glyphicons-halflings-regular.ttf
│ │ │ └── glyphicons-halflings-regular.woff
│ │ ├── javascripts
│ │ │ ├── _references.js
│ │ │ ├── bootstrap.js
│ │ │ ├── bootstrap.min.js
│ │ │ ├── jquery-1.10.2.intellisense.js
│ │ │ ├── jquery-1.10.2.js
│ │ │ ├── jquery-1.10.2.min.js
│ │ │ ├── jquery-1.10.2.min.map
│ │ │ ├── jquery.validate-vsdoc.js
│ │ │ ├── jquery.validate.js
│ │ │ ├── jquery.validate.min.js
│ │ │ ├── jquery.validate.unobtrusive.js
│ │ │ ├── jquery.validate.unobtrusive.min.js
│ │ │ ├── modernizr-2.6.2.js
│ │ │ ├── respond.js
│ │ │ └── respond.min.js
│ │ └── stylesheets
│ │ │ ├── bootstrap.css
│ │ │ ├── bootstrap.min.css
│ │ │ └── style.styl
│ ├── routes
│ │ └── index.js
│ └── views
│ │ ├── about.jade
│ │ ├── contact.jade
│ │ ├── index.jade
│ │ └── layout.jade
└── express-demo
│ ├── .ntvs_analysis.dat
│ ├── README.md
│ ├── app.js
│ ├── express-demo.njsproj
│ ├── express-demo.sln
│ ├── express-demo.v12.suo
│ ├── package.json
│ ├── public
│ ├── fonts
│ │ ├── glyphicons-halflings-regular.eot
│ │ ├── glyphicons-halflings-regular.svg
│ │ ├── glyphicons-halflings-regular.ttf
│ │ └── glyphicons-halflings-regular.woff
│ ├── javascripts
│ │ ├── _references.js
│ │ ├── bootstrap.js
│ │ ├── bootstrap.min.js
│ │ ├── jquery-1.10.2.intellisense.js
│ │ ├── jquery-1.10.2.js
│ │ ├── jquery-1.10.2.min.js
│ │ ├── jquery-1.10.2.min.map
│ │ ├── jquery.validate-vsdoc.js
│ │ ├── jquery.validate.js
│ │ ├── jquery.validate.min.js
│ │ ├── jquery.validate.unobtrusive.js
│ │ ├── jquery.validate.unobtrusive.min.js
│ │ ├── modernizr-2.6.2.js
│ │ ├── respond.js
│ │ └── respond.min.js
│ └── stylesheets
│ │ ├── bootstrap.css
│ │ ├── bootstrap.min.css
│ │ ├── style.css
│ │ └── style.styl
│ ├── routes
│ └── index.js
│ └── views
│ ├── about.jade
│ ├── contact.jade
│ ├── index.jade
│ └── layout.jade
├── package.json
└── test
└── hello.specs.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # Runtime data
6 | pids
7 | *.pid
8 | *.seed
9 |
10 | # Directory for instrumented libs generated by jscoverage/JSCover
11 | lib-cov
12 |
13 | # Coverage directory used by tools like istanbul
14 | coverage
15 |
16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17 | .grunt
18 |
19 | # Compiled binary addons (http://nodejs.org/api/addons.html)
20 | build/Release
21 |
22 | # Dependency directory
23 | # Commenting this out is preferred by some people, see
24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
25 | node_modules
26 |
27 | # Users Environment Variables
28 | .lock-wscript
29 |
--------------------------------------------------------------------------------
/.settings/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.1.0",
3 | // List of configurations. Add new configurations or edit existing ones.
4 | // ONLY "node" and "mono" are supported, change "type" to switch.
5 | "configurations": [
6 | {
7 | // Name of configuration; appears in the launch configuration drop down menu.
8 | "name": "Launch app.js",
9 | // Type of configuration. Possible values: "node", "mono".
10 | "type": "node",
11 | // Workspace relative or absolute path to the program.
12 | "program": "./ExpressMvp/bin/www",
13 | // Automatically stop program after launch.
14 | "stopOnEntry": false,
15 | // Command line arguments passed to the program.
16 | "args": [],
17 | // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
18 | "cwd": ".",
19 | // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
20 | "runtimeExecutable": null,
21 | // Environment variables passed to the program.
22 | "env": { }
23 | },
24 | {
25 | "name": "Attach",
26 | "type": "node",
27 | // TCP/IP address. Default is "localhost".
28 | "address": "localhost",
29 | // Port to attach to.
30 | "port": 5858
31 | }
32 | ]
33 | }
34 |
--------------------------------------------------------------------------------
/ExpressMvp.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.31101.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "ExpressMvp", "ExpressMvp\ExpressMvp.njsproj", "{9C5320A4-DEB2-4A7B-B1D9-B1A0A6291647}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {9C5320A4-DEB2-4A7B-B1D9-B1A0A6291647}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {9C5320A4-DEB2-4A7B-B1D9-B1A0A6291647}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {9C5320A4-DEB2-4A7B-B1D9-B1A0A6291647}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {9C5320A4-DEB2-4A7B-B1D9-B1A0A6291647}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/ExpressMvp/.ntvs_analysis.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/reverentgeek/nodejs-demos/7255daa3295b35045954d72fc5700d8de8d77709/ExpressMvp/.ntvs_analysis.dat
--------------------------------------------------------------------------------
/ExpressMvp/ExpressMvp.njsproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 11.0
5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
6 | ExpressMvp
7 | ExpressMvp
8 |
9 |
10 |
11 | Debug
12 | 2.0
13 | 9c5320a4-deb2-4a7b-b1d9-b1a0a6291647
14 | .
15 | bin\www
16 |
17 |
18 | .
19 | .
20 | v4.0
21 | {3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}
22 | ShowAllFiles
23 | 1337
24 | true
25 |
26 |
27 | true
28 |
29 |
30 | true
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | False
61 | True
62 | 0
63 | /
64 | http://localhost:48022/
65 | False
66 | True
67 | http://localhost:1337
68 | False
69 |
70 |
71 |
72 |
73 |
74 |
75 | CurrentPage
76 | True
77 | False
78 | False
79 | False
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | False
89 | False
90 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/ExpressMvp/README.md:
--------------------------------------------------------------------------------
1 | # ExpressMvp
2 |
3 |
4 |
--------------------------------------------------------------------------------
/ExpressMvp/app.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var path = require('path');
3 | var favicon = require('serve-favicon');
4 | var logger = require('morgan');
5 | var cookieParser = require('cookie-parser');
6 | var bodyParser = require('body-parser');
7 |
8 | var routes = require('./routes/index');
9 | var users = require('./routes/users');
10 |
11 | var app = express();
12 |
13 | // view engine setup
14 | app.set('views', path.join(__dirname, 'views'));
15 | app.set('view engine', 'jade');
16 |
17 | // uncomment after placing your favicon in /public
18 | //app.use(favicon(__dirname + '/public/favicon.ico'));
19 | app.use(logger('dev'));
20 | app.use(bodyParser.json());
21 | app.use(bodyParser.urlencoded({ extended: false }));
22 | app.use(cookieParser());
23 | app.use(require('stylus').middleware(path.join(__dirname, 'public')));
24 | app.use(express.static(path.join(__dirname, 'public')));
25 |
26 | app.use('/', routes);
27 | app.use('/users', users);
28 |
29 | // catch 404 and forward to error handler
30 | app.use(function (req, res, next) {
31 | var err = new Error('Not Found');
32 | err.status = 404;
33 | next(err);
34 | });
35 |
36 | // error handlers
37 |
38 | // development error handler
39 | // will print stacktrace
40 | if (app.get('env') === 'development') {
41 | app.use(function (err, req, res, next) {
42 | res.status(err.status || 500);
43 | res.render('error', {
44 | message: err.message,
45 | error: err
46 | });
47 | });
48 | }
49 |
50 | // production error handler
51 | // no stacktraces leaked to user
52 | app.use(function (err, req, res, next) {
53 | res.status(err.status || 500);
54 | res.render('error', {
55 | message: err.message,
56 | error: {}
57 | });
58 | });
59 |
60 |
61 | module.exports = app;
62 |
--------------------------------------------------------------------------------
/ExpressMvp/bin/www:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var debug = require('debug')('ExpressMvp');
3 | var app = require('../app');
4 |
5 | app.set('port', process.env.PORT || 3000);
6 |
7 | var server = app.listen(app.get('port'), function() {
8 | debug('Express server listening on port ' + server.address().port);
9 | });
10 |
--------------------------------------------------------------------------------
/ExpressMvp/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ExpressMvp",
3 | "version": "0.0.0",
4 | "private": true,
5 | "scripts": {
6 | "start": "node ./bin/www"
7 | },
8 | "description": "ExpressMvp",
9 | "author": {
10 | "name": "david",
11 | "email": ""
12 | },
13 | "dependencies": {
14 | "body-parser": "~1.8.1",
15 | "cookie-parser": "~1.3.3",
16 | "debug": "~4.1.1",
17 | "express": "~4.9.0",
18 | "jade": "~1.6.0",
19 | "morgan": "~1.10.0",
20 | "serve-favicon": "~2.1.3",
21 | "stylus": "0.42.3",
22 | "underscore": "^1.8.3"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/ExpressMvp/public/stylesheets/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding: 50px;
3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4 | }
5 | a {
6 | color: #00b7ff;
7 | }
8 |
--------------------------------------------------------------------------------
/ExpressMvp/public/stylesheets/style.styl:
--------------------------------------------------------------------------------
1 | body
2 | padding: 50px
3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif
4 | a
5 | color: #00B7FF
--------------------------------------------------------------------------------
/ExpressMvp/routes/index.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var router = express.Router();
3 |
4 | /* GET home page. */
5 | router.get('/', function (req, res) {
6 |
7 | res.render('index', { title: 'Attendees' });
8 |
9 | });
10 |
11 | module.exports = router;
12 |
--------------------------------------------------------------------------------
/ExpressMvp/routes/users.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var router = express.Router();
3 | var users = require('../src/users')( { /* our config info */ } );
4 |
5 | /* GET users listing. */
6 | router.get('/', function (req, res) {
7 | res.send('respond with a list of users');
8 | });
9 |
10 | router.get('/:id', function (req, res) {
11 | var user = users.getUserById(req.params.id);
12 | console.log("User:", user);
13 | res.render('user', user);
14 | });
15 |
16 | module.exports = router;
--------------------------------------------------------------------------------
/ExpressMvp/src/users.js:
--------------------------------------------------------------------------------
1 | var users = function(config) {
2 | var getUserById = function(id) {
3 | // Look up user in database by id
4 | return {
5 | id: id,
6 | firstName: "David",
7 | lastName: "Neal",
8 | emailAddress: "david@reverentgeek.com"
9 | };
10 | };
11 |
12 | return {
13 | getUserById: getUserById
14 | };
15 | };
16 |
17 | module.exports = users;
--------------------------------------------------------------------------------
/ExpressMvp/views/error.jade:
--------------------------------------------------------------------------------
1 | extends layout
2 |
3 | block content
4 | h1= message
5 | h2= error.status
6 | pre #{error.stack}
--------------------------------------------------------------------------------
/ExpressMvp/views/index.jade:
--------------------------------------------------------------------------------
1 | extends layout
2 |
3 | block content
4 | h1= title
5 | p Welcome to #{title}
6 | p Thank you for attending my session!
--------------------------------------------------------------------------------
/ExpressMvp/views/layout.jade:
--------------------------------------------------------------------------------
1 | doctype html
2 | html
3 | head
4 | title= title
5 | link(rel='stylesheet', href='/stylesheets/style.css')
6 | body
7 | block content
--------------------------------------------------------------------------------
/ExpressMvp/views/user.jade:
--------------------------------------------------------------------------------
1 | extends layout
2 |
3 | block content
4 | h1 User #{id}
5 | p This is #{firstName} #{lastName}
6 | p= emailAddress
7 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 David Neal
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Node.js Crash Course
2 | aka Node.js Crash Course for .NET Developers
3 |
4 | * Get the latest slides at [SpeakerDeck](https://speakerdeck.com/reverentgeek)
5 | * [About me](https://about.me/reverentgeek) | [reverentgeek.com](http://reverentgeek.com) | [@reverentgeek](https://twitter.com/reverentgeek)
6 |
7 | ## Download Node.js
8 |
9 | Download and install [Node.js](http://nodejs.org)
10 |
11 | ## Editors
12 |
13 | * [Visual Studio Code](https://code.visualstudio.com/) (free cross-platform editor for Windows, Mac OS X, and Linux)
14 | * [Visual Studio Community 2015](https://www.visualstudio.com/products/visual-studio-community-vs) (free Visual Studio IDE for Windows)
15 | * [Atom](https://atom.io/) (free cross-platform editor from GitHub)
16 |
17 | ## Tools available for Visual Studio 2012+
18 |
19 | * [Node.js Tools for Visual Studio](https://github.com/Microsoft/nodejstools)
20 | * [Package Intellisense](http://visualstudiogallery.msdn.microsoft.com/65748cdb-4087-497e-a394-2e3449c8e61e)
21 | * [Task Runner Explorer](http://visualstudiogallery.msdn.microsoft.com/8e1b4368-4afb-467a-bc13-9650572db708)
22 | * [Grunt Launcher](http://visualstudiogallery.msdn.microsoft.com/dcbc5325-79ef-4b72-960e-0a51ee33a0ff)
23 |
24 | ## Tools
25 |
26 | * [Express](http://expressjs.com/) - fast, unopinionated, minimalist web framework
27 | * [Vash](https://github.com/kirbysayshi/vash) template engine with Razor syntax
28 | * [Electron](http://electron.atom.io/) - Desktop application shell that [Atom](https://atom.io/) uses
29 | * [Edge.js GitHub project](https://github.com/tjanczuk/edge) - run .NET code/libraries from Node.js (and vice versa)
30 | * [Edge.js overview](http://tjanczuk.github.io/edge/)
31 |
32 | ## Articles
33 |
34 | * [Why Node.js is Becoming the Go-To Technology in the Enterprise](http://www.nearform.com/nodecrunch/node-js-becoming-go-technology-enterprise/) by Cian O'Maidin
35 | * [What is Node.js used for: The 2015 Node.js Overview Report](http://blog.risingstack.com/what-is-nodejs-used-for-the-2015-nodejs-overview-report/) by Gabor Nagy
36 | * [Hosting Node.js on Microsoft Azure](http://reverentgeek.com/hosting-node-js-on-microsoft-azure/) by David Neal
37 | * [Introducing Gulp, Grunt, Bower, and npm support for Visual Studio](http://www.hanselman.com/blog/IntroducingGulpGruntBowerAndNpmSupportForVisualStudio.aspx) by Scott Hanselman
38 | * [Painless SQL Server with Node.js and Seriate](http://developer.leankit.com/painless-sql-server-with-nodejs-and-seriate/) by David Neal
39 | * [UPDATED for 2015: How to install the nodejs Ghost blog software on Azure Web Apps (and the Deploy to Azure Button)](http://www.hanselman.com/blog/UPDATEDFor2015HowToInstallTheNodejsGhostBlogSoftwareOnAzureWebAppsAndTheDeployToAzureButton.aspx) by Scott Hanselman
40 |
41 | ## Even MOAR Resources
42 |
43 | * [Awesome Node.js](https://github.com/sindresorhus/awesome-nodejs/) - Curated list of Node.js packages and resources
44 | * [Node.js for Beginners](https://github.com/rockbot/node-for-beginners) - Huge list of resources for Node.js newbies
45 | * [NPM Library](https://www.npmjs.org/)
46 | * WatchMeCode [Intro to NodeJS](https://sub.watchmecode.net/downloads/intro-to-nodejs/) training videos
47 | * WatchMeCode [Pro ExpressJS](https://sub.watchmecode.net/downloads/pro-expressjs/) training videos
48 | * Pluralsight video course: [Node.js for .NET Developers](http://www.pluralsight.com/courses/nodejs-dotnet-developers)
49 | * Pluralsight video course: [RESTful Web Services with Node.js and Express](http://www.pluralsight.com/courses/node-js-express-rest-web-services)
50 | * ["Node.js in Action"](http://www.manning.com/cantelon/) by Mike Cantelon, Marc Harter, T.J. Holowaychuk and Nathan Rajlich
51 | * ["Node.js in Practice"](http://www.manning.com/young/) by Alex Young and Marc Harter
52 |
--------------------------------------------------------------------------------
/demo-modules/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "minWidth": 250,
3 | "maxWidth": 900,
4 | "minHeight": 250,
5 | "maxHeight": 1200
6 | }
7 |
--------------------------------------------------------------------------------
/demo-modules/config-example.js:
--------------------------------------------------------------------------------
1 | const Config = require( "./config" );
2 | const appConfig = new Config( "./app.json" );
3 |
4 | const mw = appConfig.get( "minWidth", 100 );
5 |
6 | console.log( mw );
7 | // output: 250
8 |
--------------------------------------------------------------------------------
/demo-modules/config.js:
--------------------------------------------------------------------------------
1 | const fs = require( "fs" );
2 |
3 | const configModule = function( path ) {
4 | const configData = fs.readFileSync( path, "utf8" );
5 | const config = JSON.parse( configData );
6 |
7 | const get = function( property, defaultValue ) {
8 | return config[ property ] || defaultValue;
9 | };
10 | const set = function( property, value ) {
11 | config[ property ] = value;
12 | };
13 | const internalFunction = function() {
14 | /* stuff */
15 | };
16 | const save = function( callback ) {
17 | internalFunction();
18 | callback();
19 | };
20 |
21 | return {
22 | get,
23 | set,
24 | save
25 | };
26 | };
27 |
28 | module.exports = configModule;
29 |
--------------------------------------------------------------------------------
/demo-modules/module-usage.js:
--------------------------------------------------------------------------------
1 | var fs = require( "fs" ); // Built-in Node.js module
2 |
3 | var express = require( "express" ); // Module installed via npm
4 |
5 | var ApiService = require( "./app/ApiService" ); // Local module
6 |
7 | var api = new ApiService( { port: 8888 } );
8 |
9 | api.someMethod( "val1", 22, function( err, results ) {
10 | if ( err ) {
11 | // Do something
12 | }
13 | // Do stuff with results
14 | } );
15 |
--------------------------------------------------------------------------------
/demo-modules/sql.js:
--------------------------------------------------------------------------------
1 | const sql = require( "seriate" );
2 |
3 | // Read from environment variables or local config file
4 | const config = { server: "127.0.0.1", user: "user1", password: "mypass", database: "mydb" };
5 | sql.setDefaultConfig( config );
6 |
7 | sql.execute( {
8 | query: "SELECT userId, email FROM accounts"
9 | } ).then( function( results ) {
10 | // Do something with the results
11 | console.log( results );
12 | } ).catch( function( err ) {
13 | console.log( "Something bad happened:", err );
14 | } );
15 |
16 |
--------------------------------------------------------------------------------
/demo-modules/temperature-example.js:
--------------------------------------------------------------------------------
1 | const t = require( "./temperature" );
2 |
3 | const c = t.boilingCelcius;
4 | const f = t.convertToFarenheit( c );
5 |
6 | console.log( `${c} C is ${f} F` );
7 | // output: 100 C is 212 F
8 |
--------------------------------------------------------------------------------
/demo-modules/temperature.js:
--------------------------------------------------------------------------------
1 | function convertToCelcius( f ) {
2 | return ( f - 32 ) * ( 5 / 9 );
3 | }
4 |
5 | function convertToFarenheit( c ) {
6 | return ( c * ( 9 / 5 ) ) + 32;
7 | }
8 |
9 | const temp = {
10 | freezingCelcius: 0,
11 | freezingFarenheit: 32,
12 | boilingCelcius: 100,
13 | boilingFarenheit: 212,
14 | convertToCelcius,
15 | convertToFarenheit
16 | };
17 |
18 | module.exports = temp;
19 |
--------------------------------------------------------------------------------
/demo1/index.js:
--------------------------------------------------------------------------------
1 | console.log( "Hello, everybody!" );
2 |
--------------------------------------------------------------------------------
/demo2/index.js:
--------------------------------------------------------------------------------
1 | function sayHello( name ) {
2 | console.log( "Hello, " + name + "!" );
3 | }
4 |
5 | sayHello( "everybody" );
6 |
--------------------------------------------------------------------------------
/demo3/hello.js:
--------------------------------------------------------------------------------
1 | var Hello = {
2 | version: 1,
3 | getHello: function( name, callback ) {
4 | var err = null;
5 | if ( name === null || name === "" ) {
6 | callback( new Error( "You must provide a valid name!" ) );
7 | } else {
8 | callback( null, "Hello, " + name + "!" );
9 | }
10 | }
11 | };
12 |
13 | module.exports = Hello;
14 |
--------------------------------------------------------------------------------
/demo3/index.js:
--------------------------------------------------------------------------------
1 | var hello = require( "./hello" );
2 |
3 | // console.log(hello);
4 |
5 | hello.getHello( "Microsoft MVP V-Conf", function( err, response ) {
6 | if ( err )
7 | throw err;
8 | console.log( "Version:", hello.version );
9 | console.log( response );
10 | } );
11 |
12 | // hello.getHello( null, function( err, response ) {
13 | // if ( err )
14 | // throw err;
15 | // console.log( response );
16 | // } );
17 |
--------------------------------------------------------------------------------
/demo4/hello.js:
--------------------------------------------------------------------------------
1 | var Hello = function( name ) {
2 | var getHello = function( callback ) {
3 | var err = null;
4 | if ( name === null || name === "" ) {
5 | callback( new Error( "You must provide a valid name!" ) );
6 | } else {
7 | callback( null, "Hello, " + name + "!" );
8 | }
9 | };
10 |
11 | return {
12 | version: 2,
13 | getHello: getHello
14 | };
15 | };
16 |
17 | module.exports = Hello;
18 |
--------------------------------------------------------------------------------
/demo4/index.js:
--------------------------------------------------------------------------------
1 | var Hello = require( "./hello" );
2 |
3 | // console.log( "Hello module:", Hello );
4 |
5 | var hello1 = Hello( "Microsoft MVP V-Conf 2015" );
6 |
7 | // console.log( "hello1 instance:", hello1 );
8 |
9 | hello1.getHello( function( err, response ) {
10 | if ( err )
11 | throw err;
12 | console.log( "Version:", hello1.version );
13 | console.log( response );
14 | } );
15 |
16 | // var hello2 = Hello( "y'all" );
17 |
18 | // hello2.getHello( function( err, response ) {
19 | // if ( err )
20 | // throw err;
21 | // console.log( "Version:", hello2.version );
22 | // console.log( response );
23 | // } );
24 |
--------------------------------------------------------------------------------
/demo5/index.js:
--------------------------------------------------------------------------------
1 | var http = require( "http" );
2 |
3 | http.createServer( function( req, res ) {
4 | res.writeHead( 200, { "Content-Type": "text/plain" } );
5 | res.end( "Hello, y'all!" );
6 | } ).listen( 3000 );
7 |
8 | console.log( "Server started o'var on port 3000" );
9 |
10 | // http.createServer( function( req, res ) {
11 | // var path = req.url.replace( /\/?(?:\?.*)?$/, "" ).toLowerCase();
12 | // switch (path) {
13 | // case "":
14 | // res.writeHead( 200, { "Content-Type": "text/plain" } );
15 | // res.end( "Homepage, y'all!" );
16 | // break;
17 | // case "/about":
18 | // res.writeHead( 200, { "Content-Type": "text/plain" } );
19 | // res.end( "About this here web site!" );
20 | // break;
21 | // default:
22 | // res.writeHead( 404, { "Content-Type": "text/plain" } );
23 | // res.end( "Cain't find it!" );
24 | // break;
25 | // }
26 | // } ).listen( 3000 );
27 |
28 | // console.log( "Server started o'var on port 3000" );
29 |
--------------------------------------------------------------------------------
/edge-demos/101-hello-world.js:
--------------------------------------------------------------------------------
1 | var edge = require('edge');
2 |
3 | var hello = edge.func(function () {/*
4 | async (input) =>
5 | {
6 | return "I tell you what I need... " + input.ToString();
7 | }
8 | */});
9 |
10 | hello('MORE CAFFEINE!!', function (err, result) {
11 | if (err) throw err;
12 | console.log(result);
13 | });
14 |
--------------------------------------------------------------------------------
/edge-demos/102-hello-file.js:
--------------------------------------------------------------------------------
1 | var edge = require('edge');
2 |
3 | var hello = edge.func('./file-demo.cs');
4 |
5 | hello('MORE CAFFEINE!!', function (err, result) {
6 | if (err) throw err;
7 | console.log(result);
8 | });
9 |
--------------------------------------------------------------------------------
/edge-demos/103-data-marshalling.js:
--------------------------------------------------------------------------------
1 | var edge = require( 'edge' );
2 |
3 | var dataToSendToDotNET = {
4 | anInteger: 1,
5 | aNumber: 3.1415,
6 | aString: 'String from Node.js',
7 | aBool: true,
8 | anObject: { a: '1' },
9 | anArray: [ 'a', 1, true ],
10 | aBuffer: new Buffer(1024)
11 | }
12 |
13 | var testMarshalling = edge.func('./data-marshalling.cs');
14 |
15 | testMarshalling(dataToSendToDotNET, function (err, result) {
16 | if (err) throw err;
17 | console.log('Data from .NET to Node.js')
18 | console.log('=========================')
19 | console.log(result);
20 | });
--------------------------------------------------------------------------------
/edge-demos/104-hello-sql.js:
--------------------------------------------------------------------------------
1 | var edge = require('edge');
2 |
3 | var getUsers = edge.func('./sql-demo.cs');
4 |
5 | var page = { currentPage: 1, pageSize: 3 };
6 |
7 | getUsers(page, function (err, result) {
8 | if (err) throw err;
9 | console.log(result);
10 | console.log('FirstName', result[0].FirstName)
11 | });
12 |
--------------------------------------------------------------------------------
/edge-demos/105-hello-assembly.js:
--------------------------------------------------------------------------------
1 | var edge = require('edge');
2 |
3 | var getUsers = edge.func({
4 | assemblyFile: '../edge-demos/bin/Debug/edge-demos.dll',
5 | typeName: 'edgedemos.DapperTests',
6 | methodName: 'QueryUsers'
7 | });
8 |
9 | var page = { currentPage: 1, pageSize: 3 };
10 |
11 | getUsers(page, function(err, res) {
12 | if (err) throw err;
13 | console.log(res);
14 | });
15 |
--------------------------------------------------------------------------------
/edge-demos/data-marshalling.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | async (input) =>
3 | {
4 | Console.WriteLine("");
5 | Console.WriteLine("Data from Node.js to .NET :");
6 | Console.WriteLine("===========================");
7 | var data = (IDictionary) input;
8 | foreach (var kv in data)
9 | {
10 | Console.Write("{0} ({1})", kv.Key, kv.Value.GetType());
11 | if (kv.Value is System.Dynamic.ExpandoObject) {
12 | var values = kv.Value as IDictionary;
13 | if (values != null) {
14 | Console.WriteLine(", Values:");
15 | foreach(var kv2 in values) {
16 | Console.WriteLine(" - {0} ({1}): {2}", kv2.Key, kv2.Value.GetType(), kv2.Value);
17 | }
18 | } else {
19 | Console.WriteLine(": dynamic");
20 | }
21 | }
22 | else if (kv.Value is System.Object[]) {
23 | var values = kv.Value as System.Object[];
24 | Console.WriteLine(", Values: ");
25 | for(var i = 0; i < values.Length; i++) {
26 | Console.WriteLine(" - {0}: {1}", values[i].GetType(), values[i]);
27 | }
28 | }
29 | else if (kv.Value is System.Byte[]) {
30 | var bytes = kv.Value as System.Byte[];
31 | Console.WriteLine(": byte array size {0:#,###}", bytes.Length);
32 | }
33 | else {
34 | Console.WriteLine(": {0}", kv.Value);
35 | }
36 | }
37 | Console.WriteLine("");
38 |
39 | var result = new {
40 | anInteger = 1,
41 | aNumber = 3.1415,
42 | sString = "String Value",
43 | aBool = true,
44 | anObject = new { a = "1", b = "2" },
45 | anArray = new int[] { 1, 2, 3 },
46 | aBuffer = new byte[1024]
47 | };
48 |
49 | return result;
50 | }
51 |
--------------------------------------------------------------------------------
/edge-demos/file-demo.cs:
--------------------------------------------------------------------------------
1 | async (input) =>
2 | {
3 | return "I tell you what I need... " + input.ToString();
4 | }
5 |
--------------------------------------------------------------------------------
/edge-demos/sql-demo.cs:
--------------------------------------------------------------------------------
1 | //#r "System.dll"
2 | //#r "System.Data.dll"
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Data;
7 | using System.Data.SqlClient;
8 | using System.Dynamic;
9 | using System.Threading.Tasks;
10 |
11 | public class Startup
12 | {
13 | public async Task