Skip to content

Instantly share code, notes, and snippets.

@churchthecat
Created January 28, 2020 16:50
Show Gist options
  • Save churchthecat/a7b43c2f6cf4f0c2b362ce5b5766642e to your computer and use it in GitHub Desktop.
Save churchthecat/a7b43c2f6cf4f0c2b362ce5b5766642e to your computer and use it in GitHub Desktop.
teachers.js
Utan: const mysql = require("promise-mysql");
const config = require("./config.json"); i början av teachers.js ger felet:
anders@andershpjobb ~/BTH/Dbwebbkurser/databas/me/kmom02/search $ node teachers.js
(node:13696) UnhandledPromiseRejectionWarning: ReferenceError: mysql is not defined
at /home/anders/BTH/Dbwebbkurser/databas/me/kmom02/search/teachers.js:11:16
at Object.<anonymous> (/home/anders/BTH/Dbwebbkurser/databas/me/kmom02/search/teachers.js:59:3)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
(node:13696) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13696) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@churchthecat
Copy link
Author

churchthecat commented Jan 28, 2020

Vidare fel när jag föröker få ut i tabell med följande kod :
// Output as formatted text in table
let str;

str  = "+-----------+---------------------+-----------+----------+\n";
str += "| Akronym   | Namn                | Avdelning |   Lön    |\n";
str += "|-----------|---------------------|-----------|----------|\n";
for (const row of res) {
    str += "| ";
    str += row.akronym.padEnd(10);
    str += "| ";
    str += (row.fornamn + " " + row.efternamn).padEnd(20);
    str += "| ";
    str += row.avdelning.padEnd(10);
    str += "| ";
    str += row.lon.toString().padStart(8);
    str += " |\n";
}
str += "+-----------+---------------------+-----------+----------+\n";
console.info(str);  

Ger felet:
(node:13826) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'toString' of undefined
at /home/anders/BTH/Dbwebbkurser/databas/me/kmom02/search/teachers.js:52:24
at
(node:13826) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13826) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

rad 52 är: str += row.lon.toString().padStart(8);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment