Nodejs-CSDN博客
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |
node是运行js的环境
node 基础命令
let uniq = require("uniq")
console.log(uniq([1, 2, 2, 3]));
模块导入导出
module.exports = {
id : 1,
log : function () {
console.log(exports === module.exports);
}
}
module.exports.name = "zhangsan";
const exp = require("./export.js");
console.log(exp);
exp.log();
文件读写
let fs = require("fs");
fs.appendFile("./file/file1.txt","777",err => {
if (err){
console.log(err);
}else {
console.log("文件写入成功");
}
});
fs.readFile("./file/file2.txt",(err, data) => {
if (err){
console.log(err);
}else {
console.log(data.toString());
}
});
console.log(__dirname);
console.log(__filename);
let path = require("path");
console.log(path.join(__dirname,"file3.txt"));
console.log(path.resolve(__dirname,"file3.txt"));
http
const http = require("http");
const server = http.createServer((req, res) => {
console.log(req.method);
console.log(req.headers.host);
const url = new URL(req.url,"http://locahost:9000");
console.log(url.searchParams.get("id"));
console.log(url.pathname);
res.setHeader("content-type","text/html;charset=utf-8");
res.write("hello");
res.end("world");
})
server.listen(9000,() => console.log("9000 服务已启动"))
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |