A path,

1. path.join & path.resolve

// path.join
const path = require('path')

// path.join: path joining function
let p = path.join('/a'.'b'.'c'.'.. /d') 
console.log(p)// a/b/d
let p1 = path.join(path.resolve(), 'a'.'b')
console.log(p1) // js file path /a/b

// path.resolve: Resolve the path from right to left, stop the first path with a /, and return to the following path
let p2 = path.resolve(__dirname)
console.log(p2) 

p3 = path.resolve('/a'.'/b'.'/c'.'d'.'./e')
console.log(p3) // c/d/eDescription:1.Path.resolve () returns the absolute path to the current file without arguments2.If there is a parameter, and there is no path starting with/in the parameter, return the combination of the absolute path and parameters3.Returns a concatenation reference between the first path encountered from right to left and its subsequent parameters: HTTPS://www.jianshu.com/p/3a713442b70b
Copy the code

Second, the fs

1. readFile && readFileSync

const fs = require('fs');
const path = require('path');

// Read file contents asynchronously
fs.readFile(path.join(__dirname, 'a.txt'), (err, data) = > {
    if (err) {
        throw new Error(err);
    }
    console.log(data);
    console.log('* * * * * * * * *')
    console.log(data.toString());
})

/ / blocking I/O
const data = fs.readFileSync(path.join(__dirname, 'a.txt'),'utf-8');
console.log(data)

// This is the test content, hello, world.
// <Buffer e8 bf 99 e6 98 af e6 b5 8b e8 af 95 e5 86 85 e5 ae b9 ef bc 8c 68 65 6c 6c 6f 2c 20 77 6f 72 6c 64 2e>
/ / * * * * * * * * *
// This is the test content, hello, world.
Copy the code

Third, the HTTP

1.createServer

const http = require('http');

const server = http.createServer();

server.on('request'.(req, res) = > {
    res.setHeader('Content-Type'.'text/html; charset=utf-8');
    res.write(`<h3>hello, world. this is a http server.</h3>`);
    res.end();
});

server.listen(8081.() = > {
    console.log('listening on 8081... ')})Copy the code