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

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.

主站蜘蛛池模板: 磴口县| 犍为县| 卢氏县| 宜丰县| 东阳市| 普格县| 沂南县| 桦南县| 奉新县| 德惠市| 威宁| 靖宇县| 安新县| 施秉县| 闽侯县| 白沙| 滕州市| 乃东县| 平原县| 靖远县| 集贤县| 惠水县| 正镶白旗| 仁寿县| 大连市| 宁南县| 额尔古纳市| 平邑县| 内乡县| 凉山| 铜陵市| 咸阳市| 任丘市| 尚志市| 民权县| 平阳县| 金湖县| 三门县| 高青县| 蛟河市| 博乐市|