Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
modul:m290:learningunits:lu08:theorie:02 [2024/10/30 14:33] vdemirmodul:m290:learningunits:lu08:theorie:02 [2024/11/18 10:31] (aktuell) cbolzern
Zeile 1: Zeile 1:
-====== LU10c - Node.js - Under Construction ======+====== 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 a node server+  - Program a node server 
 + 
 +===== Additional Materials ===== 
 +  * {{ :modul:m290:learningunits:lu08:theorie:myfirstserver.zip | myFirstServer.js as ZIP-Download}}
  
  
Zeile 38: Zeile 41:
   ** ***************************************************************************************** */   ** ***************************************************************************************** */
   // Reference: www.npmjs.com/package/mysql   // Reference: www.npmjs.com/package/mysql
 +  
   const mysql = require("mysql"); // import of the mysql-package   const mysql = require("mysql"); // import of the mysql-package
   const express = require('express'); // import of the express-package/middleware   const express = require('express'); // import of the express-package/middleware
 +  
   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 51: Zeile 54:
     password: 'SafePassword123'     password: 'SafePassword123'
   }   }
 +  
   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 61: Zeile 64:
     if (err) throw err;     if (err) throw err;
     console.log('Connected to MySQL database:', connection.config.database);     console.log('Connected to MySQL database:', connection.config.database);
- +     
-     // Preparation of the sql statement, which will be send to the database+    // Preparation of the sql statement, which will be send to the database
     var sqlstmt = 'SELECT sysdate()';     var sqlstmt = 'SELECT sysdate()';
 +    
      connection.query(sqlstmt, function (err, result) {      connection.query(sqlstmt, function (err, result) {
          // 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
 +         
          console.table(result); // We can present the result as a table          console.table(result); // We can present the result as a table
          console.log(result);   // Or as a unformated string          console.log(result);   // Or as a unformated string
  • modul/m290/learningunits/lu08/theorie/02.1730295187.txt.gz
  • Zuletzt geändert: 2024/10/30 14:33
  • von vdemir