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

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.

主站蜘蛛池模板: 河北区| 辛集市| 安溪县| 昂仁县| 雷波县| 宜春市| 常宁市| 靖江市| 宜川县| 邵阳市| 明光市| 海兴县| 德令哈市| 翼城县| 保德县| 同心县| 岐山县| 吉水县| 楚雄市| 莆田市| 吴旗县| 定边县| 文安县| 徐州市| 湖北省| 怀柔区| 义乌市| 邵阳市| 始兴县| 望城县| 仪陇县| 南投市| 涪陵区| 六枝特区| 扎赉特旗| 肇州县| 开封县| 汕尾市| 岑溪市| 宜昌市| 安徽省|