# NodeJS_图书管理系统 **Repository Path**: yaclty2/svn_test ## Basic Information - **Project Name**: NodeJS_图书管理系统 - **Description**: 测试SVN - **Primary Language**: NodeJS - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2021-04-09 - **Last Updated**: 2023-06-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 测试SVN #### 介绍 NodeJs的仓库 #### 2021-4-21 ### 回顾 内连接: 查询关联表相等的数据 外连接: 查询主表全部的数据及次表与主表相等的数据 ```mysql select * from 表名1 inner join 表名2 on 表1.列 = 表2.列 -- 内连接 left join 表名2 on 表1.列 = 表2.列 -- 左连接: left前面的是主表 right join 表名2 on 表1.列 = 表2.列 -- 左连接: right前面的是次表 ``` ### WEB 服务器对象 request:请求对象 response:相应对象 cookies:储存在用户本地终端上的数据 **实现静态服务器** ```javascript // 导入模块 const fs = require('fs'), http = require('http'); // 创建服务器 const server = http.createServer((req,res)=>{ let filePath = req.url.substr(1); // 处理请求或响应 console.log(filePath) // 如果没有任何地址表示请求首页 if(filePath.length == 0) filePath = 'index.html'; // 判断请求的文件是否存在 if(!fs.existsSync(filePath)){ res.writeHead(404); // 请求资源不存在啊 res.end('404 not found'); return; } // 获取请求资源的后缀 const ext = filePath.substr( filePath.lastIndexOf('.') + 1 ).toLowerCase(); // 根据后缀 获取对应的文件类型 let type = 'text/html'; if(ext == 'css') type = 'text/css'; else if(ext == 'js') type = 'application/javascript'; res.writeHead(200,{ 'Content-Type':type }) res.end( fs.readFileSync(filePath).toString("utf-8") ); }); // 监听端口 server.listen(3000,()=>console.log('监听到3000端口, http://localhost:3000')); ``` ##### 模板引擎的使用 - EJS 1.安装ejs模块 ```shell npm install --save ejs ``` 2.引用并使用 ```javascript // 引入模块 const ejs = require('ejs'); // 使用并编译字符串 -- 同步 const str = ejs.render(`