Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
| modul:m290:learningunits:lu08:theorie:02 [2024/10/30 14:39] – vdemir | modul:m290:learningunits:lu08:theorie:02 [2024/11/18 10:31] (aktuell) – cbolzern | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== LU10c - Node.js | + | ====== LU10c - Node.js ====== |
| ===== Learning Objectives ===== | ===== Learning Objectives ===== | ||
| - What a Node.js is | - What a Node.js is | ||
| - Which benefits a node server provides us | - Which benefits a node server provides us | ||
| - | - programm | + | - Program |
| ===== Additional Materials ===== | ===== Additional Materials ===== | ||
| Zeile 41: | Zeile 41: | ||
| ** ***************************************************************************************** */ | ** ***************************************************************************************** */ | ||
| // Reference: www.npmjs.com/ | // Reference: www.npmjs.com/ | ||
| + | | ||
| const mysql = require(" | const mysql = require(" | ||
| const express = require(' | const express = require(' | ||
| + | | ||
| const port = 3000; // ThKind of a telefon number, on which the server listens for requests | const port = 3000; // ThKind of a telefon number, on which the server listens for requests | ||
| + | | ||
| // Variable set with the db-connection credentials to connect the server to the database | // Variable set with the db-connection credentials to connect the server to the database | ||
| const config = { | const config = { | ||
| Zeile 54: | Zeile 54: | ||
| password: ' | password: ' | ||
| } | } | ||
| + | | ||
| const connection = mysql.createConnection(config) | const connection = mysql.createConnection(config) | ||
| // connection line to the database, that takes the credentials | // connection line to the database, that takes the credentials | ||
| // and returns a open line to execute sql statements | // and returns a open line to execute sql statements | ||
| + | | ||
| // function that actually connects the server to the database | // function that actually connects the server to the database | ||
| // result is successful or errormessage | // result is successful or errormessage | ||
| Zeile 64: | Zeile 64: | ||
| if (err) throw err; | if (err) throw err; | ||
| console.log(' | console.log(' | ||
| - | + | | |
| - | // Preparation of the sql statement, which will be send to the database | + | |
| var sqlstmt = ' | var sqlstmt = ' | ||
| + | | ||
| | | ||
| // the sqlstmt is send to the database | // the sqlstmt is send to the database | ||
| if (err) throw err; // if everthing is fine, i receive the resultset | if (err) throw err; // if everthing is fine, i receive the resultset | ||
| + | |||
| | | ||
| | | ||