前端学习(1345):用户的增删改查操作2

//创建http连接
const http = require('http');
//创建服务器
const app = http.createServer();
//第三方模块导入
const mongoose = require('mongoose');
//获取连接
const url = require('url');
//数据库连接地址
mongoose.connect('mongodb://localhost/playground', { useUnifiedTopology: true }).then(() => console.log('数据库连接成功')).catch(() => console.log('数据库连接失败'));
//创建用户集合
const userSchema = new mongoose.Schema({name: {type: String,required: true,minlength: 2,maxlength: 20},age: {type: Number,min: 18,max: 80},password: String,email: String,hobbies: [String]
});
//创建集合
const User = mongoose.model('User', userSchema);
//添加属性事件
app.on('request', async(req, res) => {//请求方式const method = req.method;//请求地址const { pathname } = url.parse(req.url);if (method == 'GET') {//呈现用户列表页面if (pathname == '/list') {let users = await User.find();console.log(users);let list = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title></head><body><div class="container"><h6><a href="add.html" class="btn btn-primary">添加用户</a></h6><table class="table table-striped table-bordered"><tr><td>用户名</td><td>年龄</td><td>爱好</td><td>邮箱</td><td>操作</td></tr>`;//循环users.forEach(item => {list += `<tr><td>${item.name}</td><td>${item.age}</td><td>`item.hobbies.forEach(item => {list += `<span>${item}</span>`})list += ` </td> <td>${item.email}</td><td><a href="">删除</a>|<a href="">修改</a></td></tr>`;})list += `       </table></div></body></html>`res.end(list);}} else if (method == 'POST') {}url.parse(req.url);res.end('ok');
})
app.listen(3000);

运行结果

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/420267.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

太阳光是平行光吗_“彩虹的形成是因为光的色散和光沿直线传播是一回事吗?”...

-1感谢某不愿透露姓名的高中同学提供支持。0请先解释一下你的这个问题提法可能的歧义&#xff1a;究竟是“是因为”后面的词语组成一个整体&#xff0c;还是“和”前面的词语组成一个整体呢&#xff1f;不讲清楚的话&#xff0c;答案会有一些差距。1“彩虹的形成是因为光的色散…

力扣刷题【20,21,26,27,35】

-20 有效的括号21 合并两个有序链表26 删除数组中的重复项27. 移除元素35. 搜索插入位置20 有效的括号 使用replace一直替换 package top.lel.lc.easy.valid_parentheses;import java.util.Deque; import java.util.HashMap; import java.util.LinkedList; import java.util.…

前端学习(1346):用户的增删改查操作3增加

//创建http连接 const http require(http); //创建服务器 const app http.createServer(); //第三方模块导入 const mongoose require(mongoose); //获取连接 const url require(url); // const querystring require(querystring); //数据库连接地址 mongoose.connect(mon…

【leetcode】Intersection of Two Linked Lists

Intersection of Two Linked Lists Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: A: a1 → a2↘c1 → c2 → c3↗ B: b1 → b2 → b3begin to int…

闪电shader_【Shader案例】怎样做出自然的闪电

(本次案例的效果)最近下载了一套特效&#xff0c;其中一个关于闪电制作的shader想法特别聪明&#xff0c;这里特地附上原代码&#xff0c;并教你怎么把源代码转换成连连看&#xff0c;下面开始正文。这是原本shader定义的属性&#xff1a;_TintColor(闪电的颜色)_MainTex(一张R…

MySQL8数据恢复

binlog数据恢复恢复流程恢复流程 先登录MySQL flush log flush log这样会在MySQL binglog日志目录重新生成二进制文件 查看日志文件名 binlog.000033是我刚生成的日志&#xff0c;现在操作的是binlog.000032这个文件。相当于备份了下。 基于位置恢复&#xff08;先查看位置…

前端学习(1347):用户的增删改查操作4修改

//创建http连接 const http require(http); //创建服务器 const app http.createServer(); //第三方模块导入 const mongoose require(mongoose); //获取连接 const url require(url); // const querystring require(querystring); //数据库连接地址 mongoose.connect(mon…

前端学习(1348):用户的增删改查操作5修改

//创建http连接 const http require(http); //创建服务器 const app http.createServer(); //第三方模块导入 const mongoose require(mongoose); //获取连接 const url require(url); // const querystring require(querystring); //数据库连接地址 mongoose.connect(mon…

ogg oracle 测试kafka_基于OGG的Oracle与Hadoop集群/kafka准实时同步

Oracle里存储的结构化数据导出到Hadoop体系做离线计算是一种常见数据处置手段。近期有场景需要做Oracle到Hadoop体系的实时导入&#xff0c;这里以此案例做以介绍。Oracle作为商业化的数据库解决方案&#xff0c;自发性的获取数据库事务日志等比较困难&#xff0c;故选择官方提…

50个jQuery代码段帮你成为更出色的JS开发者

http://www.jqdemo.com/525.html转载于:https://www.cnblogs.com/iqiao/p/4255515.html

parallelStream与stream

并行流&#x1f36d; 多线程并发&#x1f36d; 多线程并发 &#x1f355;stream与parallelStream 下面的代码分别用了parallelStream与stream进行迭代。获取对应的每一项值&#xff0c;和对应的线程名称。 package top.lel.jvm.sdk.stream;import java.util.List; import jav…

前端学习(1349):用户的增删改查操作6删除

//创建http连接 const http require(http); //创建服务器 const app http.createServer(); //第三方模块导入 const mongoose require(mongoose); //获取连接 const url require(url); // const querystring require(querystring); //数据库连接地址 mongoose.connect(mon…

力扣刷题【94,100,101,104】

binary tree&#x1f384;树的数据结构 // Definition for a binary tree node. public static class TreeNode {int val;TreeNode left;TreeNode right;TreeNode() {}TreeNode(int val) {this.val val;}TreeNode(int val, TreeNode left, TreeNode right) {this.val val;th…

Java, C#, Swift语法对比速查表

Java 8C# 6Swift变量类型 变量名;类型 变量名;var 变量名 : 类型;变量&#xff08;类型推断&#xff09;N/Avar 变量名初值;var 变量名初值;常量final 类型 常量名初值;readonly 类型 常量名初值;let 常量名 : 类型初值;基本类型 int short long byte double float boolean cha…

0网卡开启_中标麒麟Linux v7系统下设置双网卡bond或team绑定详细过程

中标麒麟Linux v7系统下设置双网卡bond或team绑定详细过程。所谓bond&#xff0c;就是把多个物理网卡绑定成一个逻辑网卡&#xff0c;使用同一个IP工作&#xff0c;在增加带宽的同时也可以提高冗余性&#xff0c;一般使用较多的就是来提高冗余&#xff0c;分别和不同交换机相连…

前端学习(1350):用户的增删改查操作7增删改查

demo25.js //创建http连接 const http require(http); //创建服务器 const app http.createServer(); //第三方模块导入 /* const mongoose require(mongoose); */ //获取连接 const url require(url); // const querystring require(querystring);require(./demo26.js);…

基于aop的日志记录

aop实现日志记录记录工具切面logback配置测试记录工具 目标&#xff1a; 统计rest接口请求参数&#xff0c;请求地址&#xff0c;请求IP&#xff0c;响应数据&#xff0c;响应时间。方便后续问题排查&#xff0c;以及性能的总体分析。 基于springboot会使用面向切面编程基于l…

xss防御补丁_Discuz论坛最新dom xss漏洞的解决方法

无忧主机小编在日常处理客户网站问题时&#xff0c;经常遇到网站因为程序漏洞出现的问题。网站安全的发展&#xff0c;才能使得管理者放心营运。但是比较无奈的是&#xff0c;漏洞问题貌似屡见不鲜&#xff0c;就算再强大、再常用的程序&#xff0c;都会有诸如漏洞的问题&#…

前端学习(1351)模板引擎

const template require(art-template); //绝对路径 模板中显示的数据 const path require(path); const views path.join(__dirname, index.art); const html template(views, {name: 张三,age: 20 }); console.log(html); index.art <!DOCTYPE html> <html la…

内存数据库和关系数据库之间的数据同步原理

关系数据库到内存数据库同步这部分数据同步采用增量表的方式&#xff0c;系统新增或更新的数据将生成到关系数据库的增量表中&#xff0c;程序先到这些增量表中查询数据。如果能在这些增量表中查到数据就把这些数据更新到内存数据库对应表中&#xff0c;如果查不到&#xff0c;…