- Learning Node.js Development
- Andrew Mead
- 115字
- 2021-06-30 18:56:47
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.
推薦閱讀
- 物聯網與北斗應用
- Modern JavaScript Web Development Cookbook
- 6G潛在關鍵技術(下冊)
- Building E-commerce Sites with VirtueMart Cookbook
- EDA技術與VHDL編程
- 光網絡評估及案例分析
- 互聯網基礎資源技術與應用發展態勢(2021—2023)
- 智慧城市中的移動互聯網技術
- 世界互聯網發展報告·2019
- 區塊鏈輕松上手:原理、源碼、搭建與應用
- WordPress Web Application Development
- 搶占下一個智能風口:移動物聯網
- 夢工廠之材質N次方:Maya材質手冊
- Selenium WebDriver 3 Practical Guide
- 加密與解密實戰全攻略