January 2018
Beginner
658 pages
13h 10m
English
The second way to swap world with user.username in the fs.appendFile is, using an ES6 feature known as template strings. Template strings start and end with the ` (tick) operator, which is available to the left of the 1 key on your keyboard. Then you type things as you normally would.
This means that we'll first type hello, then we'll add a space with the ! (exclamation) mark, and just before !, we will put the name:
console.log('Starting app.');const fs = require('fs');const os = require('os');var user = os.userInfo();fs.appendFile('greetings.txt', `Hello !`);
To insert a JavaScript variable inside your template string, you use the $ (dollar) sign followed by opening and closing curly braces. Then we will just reference ...
Read now
Unlock full access