├── package.json ├── index.js ├── index_before.js ├── index_after.js └── .gitignore /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodejs-ai", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "@hapi/hapi": "^19.1.1", 13 | "applicationinsights": "^1.7.3" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Hapi = require('@hapi/hapi'); 4 | 5 | const init = async () => { 6 | 7 | const server = Hapi.server({ 8 | port: 3000, 9 | host: 'localhost' 10 | }); 11 | 12 | server.route({ 13 | method: 'GET', 14 | path: '/', 15 | handler: (request, h) => { 16 | return 'Hello World!'; 17 | } 18 | }); 19 | 20 | server.route({ 21 | method: 'GET', 22 | path: '/random', 23 | handler: (request, h) => { 24 | const min = 1; 25 | const max = 100000; 26 | const rnd = Math.random() * (max - min) + min; 27 | 28 | return rnd; 29 | } 30 | }); 31 | 32 | server.route({ 33 | method: 'GET', 34 | path: '/throw', 35 | handler: (request, h) => { 36 | throw new Error("Boom goes the dynamite"); 37 | } 38 | }); 39 | 40 | await server.start(); 41 | console.log('Server running on %s', server.info.uri); 42 | }; 43 | 44 | process.on('unhandledRejection', (err) => { 45 | 46 | console.log(err); 47 | process.exit(1); 48 | }); 49 | 50 | init(); -------------------------------------------------------------------------------- /index_before.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Hapi = require('@hapi/hapi'); 4 | 5 | const init = async () => { 6 | 7 | const server = Hapi.server({ 8 | port: 3000, 9 | host: 'localhost' 10 | }); 11 | 12 | server.route({ 13 | method: 'GET', 14 | path: '/', 15 | handler: (request, h) => { 16 | return 'Hello World!'; 17 | } 18 | }); 19 | 20 | server.route({ 21 | method: 'GET', 22 | path: '/random', 23 | handler: (request, h) => { 24 | const min = 1; 25 | const max = 100000; 26 | const rnd = Math.random() * (max - min) + min; 27 | 28 | return rnd; 29 | } 30 | }); 31 | 32 | server.route({ 33 | method: 'GET', 34 | path: '/throw', 35 | handler: (request, h) => { 36 | throw new Error("Boom goes the dynamite"); 37 | } 38 | }); 39 | 40 | await server.start(); 41 | console.log('Server running on %s', server.info.uri); 42 | }; 43 | 44 | process.on('unhandledRejection', (err) => { 45 | 46 | console.log(err); 47 | process.exit(1); 48 | }); 49 | 50 | init(); -------------------------------------------------------------------------------- /index_after.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const appInsights = require("applicationinsights"); 4 | appInsights.setup("TO DO ADD INSTRUMENTATION KEY HERE") 5 | .setSendLiveMetrics(true) 6 | .start(); 7 | 8 | 9 | const Hapi = require('@hapi/hapi'); 10 | 11 | const init = async () => { 12 | 13 | const server = Hapi.server({ 14 | port: 3000, 15 | host: 'localhost' 16 | }); 17 | 18 | server.route({ 19 | method: 'GET', 20 | path: '/', 21 | handler: (request, h) => { 22 | return 'Hello World!'; 23 | } 24 | }); 25 | 26 | server.route({ 27 | method: 'GET', 28 | path: '/random', 29 | handler: (request, h) => { 30 | const min = 1; 31 | const max = 100000; 32 | const rnd = Math.random() * (max - min) + min; 33 | 34 | return rnd; 35 | } 36 | }); 37 | 38 | server.route({ 39 | method: 'GET', 40 | path: '/throw', 41 | handler: (request, h) => { 42 | throw new Error("Boom goes the dynamite"); 43 | } 44 | }); 45 | 46 | await server.start(); 47 | console.log('Server running on %s', server.info.uri); 48 | }; 49 | 50 | process.on('unhandledRejection', (err) => { 51 | 52 | console.log(err); 53 | process.exit(1); 54 | }); 55 | 56 | init(); -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/node,visualstudiocode 3 | # Edit at https://www.gitignore.io/?templates=node,visualstudiocode 4 | 5 | ### Node ### 6 | # Logs 7 | logs 8 | *.log 9 | npm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | 14 | # Diagnostic reports (https://nodejs.org/api/report.html) 15 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 16 | 17 | # Runtime data 18 | pids 19 | *.pid 20 | *.seed 21 | *.pid.lock 22 | 23 | # Directory for instrumented libs generated by jscoverage/JSCover 24 | lib-cov 25 | 26 | # Coverage directory used by tools like istanbul 27 | coverage 28 | *.lcov 29 | 30 | # nyc test coverage 31 | .nyc_output 32 | 33 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 34 | .grunt 35 | 36 | # Bower dependency directory (https://bower.io/) 37 | bower_components 38 | 39 | # node-waf configuration 40 | .lock-wscript 41 | 42 | # Compiled binary addons (https://nodejs.org/api/addons.html) 43 | build/Release 44 | 45 | # Dependency directories 46 | node_modules/ 47 | jspm_packages/ 48 | 49 | # TypeScript v1 declaration files 50 | typings/ 51 | 52 | # TypeScript cache 53 | *.tsbuildinfo 54 | 55 | # Optional npm cache directory 56 | .npm 57 | 58 | # Optional eslint cache 59 | .eslintcache 60 | 61 | # Optional REPL history 62 | .node_repl_history 63 | 64 | # Output of 'npm pack' 65 | *.tgz 66 | 67 | # Yarn Integrity file 68 | .yarn-integrity 69 | 70 | # dotenv environment variables file 71 | .env 72 | .env.test 73 | 74 | # parcel-bundler cache (https://parceljs.org/) 75 | .cache 76 | 77 | # next.js build output 78 | .next 79 | 80 | # nuxt.js build output 81 | .nuxt 82 | 83 | # rollup.js default build output 84 | dist/ 85 | 86 | # Uncomment the public line if your project uses Gatsby 87 | # https://nextjs.org/blog/next-9-1#public-directory-support 88 | # https://create-react-app.dev/docs/using-the-public-folder/#docsNav 89 | # public 90 | 91 | # Storybook build outputs 92 | .out 93 | .storybook-out 94 | 95 | # vuepress build output 96 | .vuepress/dist 97 | 98 | # Serverless directories 99 | .serverless/ 100 | 101 | # FuseBox cache 102 | .fusebox/ 103 | 104 | # DynamoDB Local files 105 | .dynamodb/ 106 | 107 | # Temporary folders 108 | tmp/ 109 | temp/ 110 | 111 | ### VisualStudioCode ### 112 | .vscode/* 113 | !.vscode/settings.json 114 | !.vscode/tasks.json 115 | !.vscode/launch.json 116 | !.vscode/extensions.json 117 | 118 | ### VisualStudioCode Patch ### 119 | # Ignore all local history of files 120 | .history 121 | 122 | # End of https://www.gitignore.io/api/node,visualstudiocode --------------------------------------------------------------------------------