Node.js的版本升级

查看本地node版本

node -v

安装n模块

npm install -g n(mac需要在命令的前面加上sudo)

升级到指定的版本/最新版本,升级之前,可以执行n ls(查看可以升级的版本)

n 8.10.1(版本号)
或者你可以安装最新的稳定版本
n stable

4.安装完成以后,检查一下是否升级成功

node -v

nodejs 搭建本地服务器 展示文件夹

const express = require('express')
const http = require('http')
const app = express()
const port = 80
var serveIndex = require('serve-index')

app.use(express.static('../'))
app.use(serveIndex('../'))

function getIPAdress() {
    let interfaces = require('os').networkInterfaces()
    for (var devName in interfaces) {
        var iface = interfaces[devName]
        for (var i = 0; i < iface.length; i++) {
            let alias = iface[i]
            if (
                alias.family === 'IPv4' &&
                alias.address !== '127.0.0.1' &&
                !alias.internal
            ) {
                // console.log(alias.address);

                return alias.address
            }
        }
    }
}

var server = http.createServer(app)

server.listen(port, () => {
    console.log(`Example app listening at http://${getIPAdress()}:${port}`)
})