-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
66 lines (52 loc) · 1.37 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const http = require('http')
const hostname = '127.0.0.1'
const port = 3000
const server = http.createServer((req, res) => {
res.statusCode = 200
res.setHeader('Content-Type', 'text/plain')
res.end('你好世界\n')
})
console.log(process.env.NODE_ENV, "===env===");
process.argv.forEach((val, index) => {
console.log(`${index}: ${val}`)
})
const oranges = ['橙子', '橙子']
const apples = ['苹果']
oranges.forEach(fruit => {
console.count(fruit)
})
apples.forEach(fruit => {
console.count(fruit)
})
const function2 = () => console.trace()
const function1 = () => function2()
function1()
server.listen(port, hostname, () => {
console.log(`服务器运行在 http://${hostname}:${port}/`)
})
const doSomething = () => console.log('测试')
const measureDoingSomething = () => {
console.time('doSomething()')
//做点事,并测量所需的时间。
doSomething()
console.timeEnd('doSomething()')
}
measureDoingSomething()
const x = 'x'
const y = 'y'
console.log(x, y)
// 为输出着色
console.log('\x1b[33m%s\x1b[0m', '你好')
// npm install chalk
const chalk = require('chalk')
console.log(chalk.yellow('你好'))
// 创建进度条
// npm install progress
const ProgressBar = require('progress')
const bar = new ProgressBar(':bar', { total: 10 })
const timer = setInterval(() => {
bar.tick()
if (bar.complete) {
clearInterval(timer)
}
}, 100)