官术网_书友最值得收藏!

Concatenating user.username

The first way is to remove world! and concatenate user.username. Then we can concatenate another string using the + (plus) operator, as shown in the following code:

console.log('Starting app.');

const fs = require('fs');
const os = require('os');

var user = os.userInfo();

fs.appendFile('greetings.txt', 'Hello' + user.username + '!');

Now if we run this, everything is going to work as expected. Over in Terminal, we can rerun our app. It prints Starting app:

Over in the greetings.txt file, you should see something like Hello Gary! printing to the screen, as shown here:

Using the fs module and the os module, we were able to grab the user's username, create a new file, and store it.

主站蜘蛛池模板: 广平县| 龙门县| 富锦市| 沛县| 辉南县| 蓬安县| 墨江| 尤溪县| 堆龙德庆县| 高要市| 专栏| 徐州市| 界首市| 新化县| 当雄县| 夏津县| 潞西市| 沁源县| 新蔡县| 淮阳县| 凤凰县| 文登市| 寿阳县| 宕昌县| 西宁市| 翁牛特旗| 进贤县| 临沂市| 雷波县| 宁乡县| 新民市| 彭阳县| 中卫市| 南漳县| 望奎县| 台中市| 紫阳县| 边坝县| 宜宾县| 五原县| 蒲江县|