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

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.

主站蜘蛛池模板: 大石桥市| 万山特区| 禹州市| 南汇区| 崇左市| 滨海县| 崇州市| 满洲里市| 武安市| 临邑县| 正镶白旗| 来宾市| 中西区| 天峨县| 祁东县| 恩平市| 阿瓦提县| 图木舒克市| 廊坊市| 潮安县| 牟定县| 晋江市| 巴中市| 平顺县| 砀山县| 启东市| 奉节县| 岫岩| 增城市| 尼木县| 南康市| 明光市| 凤山县| 宁蒗| 米脂县| 衡山县| 且末县| 秭归县| 岳池县| 乌拉特前旗| 平阴县|