- 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.
推薦閱讀
- 黑客攻防實戰技術完全手冊:掃描、嗅探、入侵與防御
- Cisco OSPF命令與配置手冊
- 物聯網安全:理論、實踐與創新
- SEO 20日
- INSTANT PhpStorm Starter
- Go Web Scraping Quick Start Guide
- SSL VPN : Understanding, evaluating and planning secure, web/based remote access
- WordPress Web Application Development
- bash網絡安全運維
- 計算機網絡技術
- 物聯網
- Microservices Development Cookbook
- 現場總線與工業以太網及其應用技術(第2版)
- 網絡安全和信息化黨政領導干部一本通
- Hands-On Full Stack Web Development with Aurelia