node 基础
作者:互联网
使用 vscore 写 node 的配置文件
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Node",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/main.js",
"args": [
"-xxxxxx=xxxxxx",
"-xxxxxx=xxxxxx"
],
},
{
"name": "Launch_Go",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/admin/build/main.go",
"env": {
"CONSUL_IP": "127.0.0.1:8500"
}
// "args": ["--conf", "${workspaceFolder}/admin/build/config.yaml"]
// "args": ["--svr", "display"]
}
]
}
node 特点
- 事件驱动
- 非阻塞 IO 模式(异步)
- 轻量和高效
模块的导出与导入
模块的导出
class User {
constructor() {
this.userName = "小明"
this.passWord = "123456"
}
}
module.exports = User
模块的导入
const User = require("./user")
let user1=new User()
console.log(user1)
文件的读取
const fs = require("fs")
// 同步
const content = fs.readFileSync('hellow.txt', { flag: "r", encoding: "utf-8" })
console.log(content.toString())
console.log("*************************")
// 异步
fs.readFile("hellow.txt", { flag: "r", encoding: "utf-8" }, function (err, data) {
if (err) {
console.log(err)
} else {
console.log(data)
}
})
标签:node,fs,console,log,基础,User,xxxxxx 来源: https://www.cnblogs.com/rush-peng/p/16393354.html