Chapter 2: arrow functions

This commit is contained in:
Beth Griggs 2020-05-21 12:45:14 +01:00
parent 85007a6879
commit d8d40e12e5
No known key found for this signature in database
GPG Key ID: D7062848A1AB005C
6 changed files with 14 additions and 21 deletions

View File

@ -1,5 +0,0 @@
first(args, function () {
second(args, function () {
third(args, function () {});
});
});

View File

@ -3,7 +3,7 @@ const path = require("path");
const filepath = path.join(process.cwd(), "hello.txt");
fs.readFile(filepath, "utf8", function (err, contents) {
fs.readFile(filepath, "utf8", (err, contents) => {
if (err) {
return console.log(err);
}

View File

@ -3,14 +3,14 @@ const path = require("path");
const filepath = path.join(process.cwd(), "hello.txt");
fs.readFile(filepath, "utf8", function (err, contents) {
fs.readFile(filepath, "utf8", (err, contents) => {
if (err) {
return console.log(err);
}
console.log("File Contents:", contents);
const upperContents = contents.toUpperCase();
fs.writeFile(filepath, upperContents, function (err) {
fs.writeFile(filepath, upperContents, (err) => {
if (err) throw err;
console.log("File updated.");
});

View File

@ -3,7 +3,7 @@ const path = require("path");
const filepath = path.join(process.cwd(), "hello.txt");
fs.readFile(filepath, "utf8", function (err, contents) {
fs.readFile(filepath, "utf8", (err, contents) => {
if (err) {
return console.log(err);
}

View File

@ -3,7 +3,7 @@ const path = require("path");
const filepath = path.join(process.cwd(), "hello.txt");
fs.readFile(filepath, "utf8", function (err, contents) {
fs.readFile(filepath, "utf8", (err, contents) => {
if (err) {
return console.log(err);
}

View File

@ -1,5 +1,5 @@
require("dotenv").config();
const mysql = require("mysql");
require("dotenv").config();
const db = mysql.createConnection({
user: process.env.DB_MYSQL_USER,
@ -9,12 +9,11 @@ const db = mysql.createConnection({
db.query("CREATE DATABASE tasks");
db.query("USE tasks");
db.query(
"CREATE TABLE tasks.tasks (" +
"id INT NOT NULL AUTO_INCREMENT, " +
"task TEXT NOT NULL, PRIMARY KEY ( id )" +
")"
);
db.query(`
CREATE TABLE tasks.tasks (
id INT NOT NULL AUTO_INCREMENT,
task TEXT NOT NULL, PRIMARY KEY ( id ))
`);
const ignore = new Set(["ER_DB_CREATE_EXISTS", "ER_TABLE_EXISTS_ERROR"]);
@ -25,16 +24,15 @@ db.on("error", (err) => {
db.query(`
INSERT INTO tasks.tasks (task)
VALUES ("Walk the dog");
VALUES ("Walk the dog.");
`);
db.query(
`
SELECT * FROM tasks.tasks;
`,
(err, results) => {
(err, results, fields) => {
console.log(results);
db.end();
}
);
db.end();