Chapter 2: arrow functions
This commit is contained in:
parent
85007a6879
commit
d8d40e12e5
@ -1,5 +0,0 @@
|
||||
first(args, function () {
|
||||
second(args, function () {
|
||||
third(args, function () {});
|
||||
});
|
||||
});
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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.");
|
||||
});
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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();
|
||||
Loading…
x
Reference in New Issue
Block a user