基于Nodejs+vue开发实现酒店管理系统

简介: 基于Nodejs+vue开发实现酒店管理系统

项目编号:BS-QD-KS-002

一,项目简介


本项目使用纯前端技术开发实现一个酒店管理系统,前端采用VUE开发实现,后台通过NODEJS作为服务器开发实现,主要实现了酒店管理系统中的:房型管理、房间管理、顾客管理、订单管理等,用户可以注册并登陆后进行相应的管理操作。主要说明


前后端分离技术

前端使用vuejs,ElementUI,axios前后端通信,图标使用了ElementUI自带的图标还有font-awesome.css的图标库, 阿里的iconfont图标库也不错,这里没用。

后端使用了nodejs,nodejs采用了Express框架,orm采用的是Sequelize操作数据库(效率极高),restful风格的Api, 跨域是由后端解决的,采用的是nodejs的cors模块(比较方便)。

数据库采用了mysql5.2(建议大家换成最新的mysql版本)

使用jsonwebtoken验证用户调用api的权限,增加接口的安全性,防止恶意攻击接口,串改数据。

主要界面里面的图片主要使用的是网上的图片,免费而且美观。

二,环境介绍


语言环境:nodejs

数据库: mysql5.7

应用服务器:nodejs

开发工具:IDEA或vscode

开发技术:nodejs+vue+elementUI

三,系统展示


用户注册

image.png

用户登陆

image.png

房间管理

image.png

image.png

房型管理

image.png

image.png

订单管理

image.png

image.png

订单管理

image.png

image.png

四,核心代码展示


1.
const { Op } = require('sequelize')//nodejs的sequelize模块
const express = require('express')//express框架
const admin = require('../crud/table/admin.js')//引入管理员信息表
const token = require('../comment/token.js')//引入token模块
const adminRouter = express.Router()//express路由
adminRouter.post('/register',(req,res) =>{//管理员注册
    const { adminId, adminName, adminPassword } = req.body;
    admin.findOne({
        where:{
            adminId:adminId
        }
    })
    .then(data =>{
        if(data){
            res.status(200).json({
                msg:'该用户已经注册',
                success:false
            })
            return new Promise(() =>{})
        }else{
            return admin.create({
                adminId, adminName, adminPassword
            })
        }
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'管理员注册成功!',
            admin:data.get()
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'内部服务器错误!'
        })
    })
})
adminRouter.get('/login',(req,res) =>{//登录
    const { adminId, adminPassword } = req.query;
    let adminInfo;
    admin.findOne({
        where:{
            adminId
        }
    })
    .then(data =>{
        if(data){
            if(data.get().adminPassword==adminPassword){
                adminInfo = data.get();
                return token.setToken(data.get())
            }else{
                res.status(200).json({
                    success:false,
                    msg:'用户密码错误!'
                });  
                return new Promise(() =>{})
            }
        }else{
           res.status(200).json({
               success:false,
               msg:'该用户还未注册!'
           })
           return new Promise(() =>{})
        }
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            admin:adminInfo,
            token:data,
            msg:'登录成功!'
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'内部服务器出错!'
        })
    })
})
adminRouter.put('/update',(req,res) =>{//修改管理员信息
    const { adminId, adminName, adminPassword, adminSex, adminAge } = req.body;
    admin.findOne({
        where:{
            adminId,adminPassword
        }
    })
    .then(data =>{
        if(data){
           return admin.update({
                    adminName,adminSex,adminAge
                },{
                    where:{
                        adminId,adminPassword
                    }
                })
        }else{
            res.status(200).json({
                success:false,
                msg:'管理员账号或者密码错误!'
            })
            return new Promise(() =>{})
        }
    })
    .then(data =>{
        return admin.findOne({
            where:{
                adminId,adminPassword
            }
        })
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'管理员信息修改成功!',
            admin:data.get()
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
adminRouter.delete('/del',(req,res) =>{
    const { adminId } = req.body || req.query;
    admin.destroy({
        where:{
            adminId
        }
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'删除成功!'
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'删除失败!'
        })
    })
})
module.exports = adminRouter;

const { Op } = require('sequelize')//nodejs的sequelize模块
const express = require('express')//express框架
const customer = require('../crud/table/customer.js')//引入用户表
const customerRouter = express.Router()//express路由
customerRouter.post('/add',(req,res) =>{//用户注册
    const { customerIdCard, customerName, customerSex, customerPhoneNumber } = req.body;
    customer.findOne({
        where:{
            customerIdCard
        }
    })
    .then(data =>{
        if(data){
            res.status(200).json({
                success:false,
                msg:'该用户已经注册!'
            })
            return new Promise(() =>{})
        }else{
            return customer.create({
                customerIdCard, customerName, customerSex, customerPhoneNumber
            })
        }
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'用户信息录入成功!',
            customer:data.get()
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'内部服务器错误!'
        })
    })
})
// customerRouter.get('/login',(req,res) =>{//用户登录
//     const { customerIdCard, cust}
// })
customerRouter.put('/update',(req,res) =>{//用户基本信息修改
    const { customerIdCard, customerName, customerSex, customerPhoneNumber } = req.body;
    customer.findOne({
        where:{
            customerIdCard:{
                [Op.eq]:customerIdCard
            }
        }
    })
    .then(data =>{
        if(data){
            return customer.update({
                customerName, customerSex, customerPhoneNumber
            },{
               where:{
                    customerIdCard:{
                        [Op.eq]:customerIdCard
                    }
               }
            })
        }else{
            res.status(200).json({
                success:false,
                msg:'该用户还未注册!'
            })
            return new Promise(() =>{})
        }
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'用户信息修改成功!',
            customer:data.get()
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器出错!'
        })
    }) 
}) 
customerRouter.delete('/del',(req,res) =>{//删除用户
    const { customerIdCard } = req.body;
    customer.destroy({
        where:{
            customerIdCard
        }
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'用户删除成功!'
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
customerRouter.put('/updatevip',(req,res) =>{//购买会员
    const { customerIdCard, level } = req.body;
    customer.findOne({
        where:{
            customerIdCard
        }
    })
    .then(data =>{
        if(data){
            return customer.update({
                level
            },{
                where:{
                    customerIdCard
                }
            })
        }else{
            res.status(200).json({
                success:false,
                msg:'该用户未注册!'
            })
            return new Promise(() =>{})
        }
    })
    .then(data =>{
        return customer.findOne({
            where:{
                customerIdCard
            }
        })
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'vip更改成功!',
            customer:data.get()
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
customerRouter.put('/updatemoney',(req,res) =>{//修改用户总消费金额
    const { customerIdCard, money} = req.body;
    customer.findOne({
        where:{
            customerIdCard
        }
    })
    .then(data =>{
        if(data){
            let oldMoney = data.get().totalAmount;
            let newMoney = oldMoney + money;
            return customer.update({
                totalAmount: newMoney
            },{
                where:{
                    customerIdCard
                }
            })
        }else{
            res.status(200).json({
                success:false,
                msg:'该用户为注册!'
            })
        }
    })
    .then(data =>{
        return customer.findOne({
            where:{
                customerIdCard
            }
        })
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'用户消费金额修改成功!'
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
customerRouter.get('/getAllCustomer',(req,res) =>{//查询所有顾客
    customer.findAndCountAll()
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'顾客信息查询成功!',
            customerList:data.rows.map(item =>{
                return item.get()
            }),
            count:data.count
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器出错!'
        })
    })
})
customerRouter.get('/queryCustomer',(req,res) =>{//模糊查询顾客信息
    const { queryName } = req.query;
    customer.findAndCountAll({
        where:{
            customerName:{
                [Op.like]:'%'+queryName+'%'
            }
        }
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'顾客信息查询成功!',
            customerList:data.rows.map(item =>{
                return item.get()
            }),
            count:data.count
        })
    })
    .then(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器出错!'
        })
    })
})
module.exports = customerRouter;
const express = require('express')//express框架
const { Op } = require('sequelize')//nodejs的sequelize模块
const order = require('../crud/table/myorder.js')//引入订单信息表
const customer = require('../crud/table/customer.js')//引入顾客信息表
const room = require('../crud/table/room.js')//引入房间信息表
order.hasOne(customer,{ sourceKey:'customerIdCard', foreignKey:'customerIdCard' })
order.hasOne(room,{ sourceKey:'roomNumber', foreignKey:'roomNumber' })
const orderRouter = express.Router()
orderRouter.post('/add',(req,res) =>{//创建订单
    console.log(req.body)
    const { orderNumber, orderStatus,customerIdCard,roomNumber,
            checkInTime,checkOutTime,totalMoney,remarks
        } = req.body;
    order.findOne({
        where:{
            orderNumber
        }
    })
    .then(data =>{
        if(data){
            res.status(200).json({
                success:false,
                msg:'该订单已经存在!'
            })
            return new Promise(() =>{})
        }else{
            return customer.findOne({
                where:{
                    customerIdCard
                }
            })
        }
    })
    .then(data =>{
        if(data){
            return room.update({
                    roomStatus:'已入住'
            },{
                where:{
                        roomNumber
                }
            })
        }else{
            res.status(200).json({
                success:false,
                msg:'该用户还未注册!'
            });
            return new Promise(() =>{});
        }
    })
    .then(data =>{
        return order.create({
            orderNumber, orderStatus,customerIdCard,roomNumber,
            checkInTime,checkOutTime,totalMoney,remarks
        })
    })
    .then(data =>{
        res.status(200).json({
            success:'true',
            msg:'订单创建成功!'
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'内部服务器出错!'
        })
    })
})
orderRouter.delete('/del',(req,res) =>{//删除订单
    const { orderNumber } = req.body;
    order.findOne({
        where:{
            orderNumber
        }
    })
    .then(data =>{
        if(data){
            return order.destroy({
                where:{
                    orderNumber
                }
            })
        }else{
            res.status(200).json({
                success:false,
                msg:'该订单不存在!'
            })
            return new Promise(() =>{})
        }
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'删除成功!'
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
orderRouter.put('/update',(req,res) =>{//修改订单状态
    const { orderStatus, orderNumber,totalMoney,roomNumber } = req.body;
    order.findOne({
        where:{
            orderNumber
        }
    })
    .then(data =>{
        if(data){
            return room.update({
                roomStatus:'未入住'
            },{
                where:{
                    roomNumber
                }
            })
        }else{
            res.status(200).json({
                success:false,
                msg:'该订单不存在!'                
            })
            return new Promise(() =>{})
        }
    })
    .then(data =>{
        return order.update({
            orderStatus,totalMoney
        },{
            where:{
                orderNumber
            }
        })
    })
    .then(data =>{
        return order.findOne({
            where:{
                orderNumber
            }
        })
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'订单修改成功!',
            order:data.get()
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
orderRouter.get('/getAllOrder',(req,res) =>{//查询所有订单
    const { pageSize, offset } = req.query;
    order.findAndCountAll({
        limit:pageSize,
        offset:offset,
        include:[
            {
                model:customer,
                foreignKey:'customerIdCard',
                attributes:['customerName','customerSex','customerVipLevel','customerPhoneNumber','totalAmount']
            },
            {
                model:room,
                foreignKey:'roomNumber',
                attributes:['type','remarks']
            }
        ]
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'所有订单查询成功!',
            orderList:data.rows.map(item =>{
                return item.get()
            }),
            count:data.count
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
orderRouter.get('/getAllNotPayOrder',(req,res) =>{//查询所有未支付的订单
    const { pageSize, offset } = req.query;
    order.findAndCountAll({
        limit:pageSize,
        offset:offset,
        where:{
            orderStatus:{
                [Op.eq]:'未支付'
            }
        },
        include:[
            {
                model:customer,
                foreignKey:'customerIdCard',
                attributes:['customerName','customerSex','customerVipLevel','customerPhoneNumber','totalAmount']
            },
            {
                model:room,
                foreignKey:'roomNumber',
                attributes:['type']
            }
        ]
    })
    .then(data  =>{
        res.status(200).json({
            success:true,
            msg:'未支付订单查询成功!',
            orderList:data.rows.map(item =>{
                return item.get()
            }),
            count:data.count,
            pageSize:pageSize,
            offset:offset
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
orderRouter.get('/getAllPayOrder',(req,res) =>{//查询所有已支付的订单
    const { pageSize, offset } = req.query;
    order.findAndCountAll({
        limit:pageSize,
        offset:offset,
        where:{
            orderStatus:{
                [Op.eq]:'已支付'
            }
        },
        include:[
            {
                model:customer,
                foreignKey:'customerIdCard',
                attributes:['customerName','customerSex','customerVipLevel','customerPhoneNumber','totalAmount']
            },
            {
                model:room,
                foreignKey:'roomNumber',
                attributes:['type']
            }
        ]
    })
    .then(data  =>{
        res.status(200).json({
            success:true,
            msg:'未支付订单查询成功!',
            orderList:data.rows.map(item =>{
                return item.get()
            }),
            count:data.count,
            pageSize:pageSize,
            offset:offset
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
orderRouter.get('/getStatusOrder',(req,res) =>{//查询所有该状态的订单
    const { pageSize, offset, orderStatus } = req.query;
    order.findAndCountAll({
        limit:pageSize,
        offset:offset,
        where:{
            orderStatus:{
                [Op.eq]:orderStatus
            }
        },
        include:[
            {
                model:customer,
                foreignKey:'customerIdCard',
                attributes:['customerName','customerSex','customerVipLevel','customerPhoneNumber','totalAmount']
            },
            {
                model:room,
                foreignKey:'roomNumber',
                attributes:['type']
            }
        ]
    })
    .then(data  =>{
        res.status(200).json({
            success:true,
            msg:'状态订单查询成功!',
            orderList:data.rows.map(item =>{
                return item.get()
            }),
            count:data.count,
            pageSize:pageSize,
            offset:offset
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
module.exports = orderRouter;
const express = require('express')//express框架
const { Op } = require('sequelize')//nodejs的sequelize模块
const room = require('../crud/table/room.js')//引入放假信息表
const roomType = require('../crud/table/roomType.js')//引入所有房间类型表
room.hasOne(roomType,{ sourceKey:'type',foreignKey:'type'})//每个房间都有一个房间类型
const roomRouter = express.Router()
roomRouter.post('/add',(req,res) =>{//添加房间
    const { roomNumber, type, roomStatus, remarks } = req.body;
    room.findOne({
        where:{
            roomNumber
        }
    })
    .then(data =>{
        if(data){
            res.status(200).json({
                success:false,
                msg:'该房间已经存在!'
            })
            return new Promise(() =>{})
        }else{
            return room.create({
                roomNumber, type, roomStatus, remarks
            })
        }
    })
    .then(data =>{
        return room.findOne({
            where:{
                roomNumber
            },
            include:[{
                model:roomType,
                foreignKey:'type',
                attributes:['price','url']
            }]
        })
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'房间添加成功!',
            room:data.get()
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
roomRouter.delete('/del',(req,res) =>{
    const { roomNumber } = req.body;
    room.findOne({
        where:{
            roomNumber
        }
    })
    .then(data =>{
        if(data){
            return room.destroy({
                where:{
                    roomNumber
                }
            })
        }else{
            res.status(200).json({
                success:false,
                msg:'房间删除失败!'
            })
            return new Promise(() =>{})
        }
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'该房间删除成功!'
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
roomRouter.put('/update',(req,res) =>{//修改房间信息
    const { roomNumber, type, roomStatus,remarks } = req.body;
    room.findOne({
        where:{
            roomNumber
        }
    })
    .then(data =>{
        if(data){
            return room.update({
                type, roomStatus,remarks
            },{
                where:{
                    roomNumber
                }
            })
        }else{
            res.status(200).json({
                success:false,
                msg:'该房间不存在!'
            })
            return new Promise(() =>{})
        }
    })
    .then(data =>{
        return room.findOne({
            where:{
                roomNumber
            }
        })
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'房间信息修改成功!',
            room:data.get()
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误'
        })
    })
})
roomRouter.get('/getAllRoom',(req,res) =>{//获取所有房间信息
    const { pageSize, offset } = req.query;
    room.findAndCountAll({
        limit:pageSize,
        offset:offset
    })
    .then(data =>{
        let roomList = data.rows.map(item =>{
            return item.get()
        })
        res.status(200).json({
            success:true,
            msg:'房间信息查询成功!',
            roomList:roomList,
            count:data.count
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
roomRouter.get('/getOneRoom',(req,res) =>{//获取某个房间号的房间信息
    const { roomNumber } = req.query;
    room.findOne({
        where:{
            roomNumber
        }
    })
    .then(data =>{
        if(data){
            res.status(200).json({
                success:true,
                msg:'房间查询成功!',
                room:data.get()
            })
        }else{
            res.status(200).json({
                success:false,
                msg:'未查询到该房间信息'
            })
        }
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
roomRouter.get('/getNotInRoom',(req,res) =>{//获取未入住房间信息
    const { pageSize, offset } = req.query;
    room.findAndCountAll({
        limit:pageSize,
        offset:offset,
        where:{
            roomStatus:{
                [Op.eq]:'未入住'
            }
        }
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'未入住房间查询成功!',
            roomList:data.rows.map(item =>{
                return item.get()
            }),
            count:data.count
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
roomRouter.get('/getInRoom',(req,res) =>{//查询已入住房间信息
    const { pageSize, offset } = req.query;
    room.findAndCountAll({
        limit:pageSize,
        offset:offset,
        where:{
            roomStatus:{
                [Op.eq]:'已入住'
            }
        }
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'已入住房间查询成功!',
            roomList:data.rows.map(item =>{
                return item.get()
            }),
            count:data.count
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
roomRouter.get('/getAllRoomPrice',(req,res) =>{//查询所有的房间以及价格
    const { pageSize, offset } = req.query;
    room.findAndCountAll({
        limit:pageSize,
        offset:offset,
        include:[{
            model:roomType,
            foreignKey:'type',
            attributes:['price','url']
        }]
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'房间信息查询成功!',
            roomList:data.rows.map(item =>{
                return item.get()
            }),
            count:data.count
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器内部错误!'
        })
    })
})
roomRouter.get('/getAllNotINRoomPrice',(req,res) =>{//获取所有未入住的房间信息
    const { pageSize, offset } = req.query;
    room.findAndCountAll({
        limit:pageSize,
        offset:offset,
        where:{
            roomStatus:{
                [Op.eq]:'未入住'
            }
        },
        include:[{
            model:roomType,
            foreignKey:'type',
            attributes:['price','url']
        }]
    })
    .then(data =>{
       res.status(200).json({
           success:true,
           msg:'房间信息查询成功!',
           roomList:data.rows.map(item =>{
               return item.get()
           }),
           count:data.count
       })
    })
})
roomRouter.get('/getAllINRoomPrice',(req,res) =>{//获取所有已入住的房间信息
    const { pageSize, offset } = req.query;
    room.findAndCountAll({
        limit:pageSize,
        offset:offset,
        where:{
            roomStatus:{
                [Op.eq]:'已入住'
            }
        },
        include:[{
            model:roomType,
            foreignKey:'type',
            attributes:['price','url']
        }]
    })
    .then(data =>{
       res.status(200).json({
           success:true,
           msg:'房间信息查询成功!',
           roomList:data.rows.map(item =>{
               return item.get()
           }),
           count:data.count
       })
    })
})
roomRouter.get('/getAllRoomTypePrice',(req,res) =>{
    const { pageSize, offset, type } = req.query;
    room.findAndCountAll({
        where:{
           type:{
               [Op.eq]:type
           }
        },
        include:[{
            model:roomType,
            foreignKey:'type',
            attributes:['price','url']
        }]
    })
    .then(data =>{
        res.status(200).json({
            success:true,
            msg:'房型查询成功!',
            roomList:data.rows.map(item =>{
                return item.get()
            }),
            count:data.count
        })
    })
    .catch(err =>{
        res.status(200).json({
            success:false,
            msg:'服务器出错!'
        })
    })
})
roomRouter.get('/getAllStatusRoom',(req,res) =>{//获取所有该状态的房间信息
    const { pageSize, offset, roomStatus } = req.query;
    room.findAndCountAll({
        limit:pageSize,
        offset:offset,
        where:{
            roomStatus:{
                [Op.eq]:roomStatus
            }
        },
        include:[{
            model:roomType,
            foreignKey:'type',
            attributes:['price','url']
        }]
    })
    .then(data =>{
       res.status(200).json({
           success:true,
           msg:'房间信息查询成功!',
           roomList:data.rows.map(item =>{
               return item.get()
           }),
           count:data.count
       })
    })
})
module.exports = roomRouter

五,项目总结


相关文章
|
5天前
|
监控 JavaScript API
局域网监控软件的实时通知系统:利用Node.js和WebSocket实现即时消息推送
本文介绍了如何使用Node.js和WebSocket构建局域网监控软件的实时通知系统。实时通知对于网络安全和家庭监控至关重要,能即时发送监控数据变化的通知,提高响应速度。通过Node.js创建WebSocket服务器,当数据变化时,监控软件发送消息至服务器,服务器随即推送给客户端。此外,还展示了如何利用Node.js编写API,自动将监控数据提交到网站,便于用户查看历史记录,从而提升监控体验。
34 3
|
14天前
|
JavaScript 前端开发 IDE
【TypeScript技术专栏】TypeScript与Node.js后端开发
【4月更文挑战第30天】TypeScript在Node.js后端开发中日益重要,作为JavaScript超集,它提供静态类型检查和面向对象编程,增强代码可靠性和维护性。集成TypeScript能带来类型安全、更好的IDE体验、易于维护的代码以及增强工具支持。通过安装TypeScript编译器、编写TypeScript文件、配置TSconfig,开发者可以在Node.js项目中利用其高级特性,提高代码质量和开发效率。实践案例显示,TypeScript能确保路由处理器的类型正确,降低错误率。随着社区发展,TypeScript成为提升Node.js开发体验的推荐选择。
|
15天前
|
缓存 JavaScript 前端开发
Node.js的模块系统:CommonJS模块系统的使用
【4月更文挑战第29天】Node.js采用CommonJS作为模块系统,每个文件视为独立模块,通过`module.exports`导出和`require`引入实现依赖。模块有独立作用域,保证封装性,防止命名冲突。引入的模块会被缓存,提高加载效率并确保一致性。利用CommonJS,开发者能编写更模块化、可维护的代码。
|
16天前
|
JavaScript 前端开发 BI
采用前后端分离Vue,Ant-Design技术开发的(手麻系统成品源码)适用于三甲医院
开发环境 技术架构:前后端分离 开发语言:C#.net6.0 开发工具:vs2022,vscode 前端框架:Vue,Ant-Design 后端框架:百小僧开源框架 数 据 库:sqlserver2019
28 4
采用前后端分离Vue,Ant-Design技术开发的(手麻系统成品源码)适用于三甲医院
|
18天前
|
JavaScript 前端开发 关系型数据库
node+vue3+mysql前后分离开发范式——实现视频文件上传并渲染
node+vue3+mysql前后分离开发范式——实现视频文件上传并渲染
26 1
|
18天前
|
JavaScript 前端开发 API
node+vue3+mysql前后分离开发范式——实现对数据库表的增删改查
node+vue3+mysql前后分离开发范式——实现对数据库表的增删改查
36 1
|
20天前
|
Web App开发 JavaScript 前端开发
js开发:请解释什么是Node.js,以及它的应用场景。
Node.js是基于V8引擎的JavaScript运行时,用于服务器端编程。以其事件驱动、非阻塞I/O模型著称,适用于高并发和实时应用。常见用途包括:构建Web服务器、实时应用(如聊天)、API服务、微服务、工具和命令行应用,以及搭配Electron开发桌面软件。
20 1
|
29天前
|
JavaScript API
node.js之模块系统
node.js之模块系统
|
1月前
|
缓存 并行计算 JavaScript
【Node系列】模块系统
Node.js 的模块系统是其核心特性之一,允许开发者编写可复用的代码,并通过简单的导入和导出机制来共享和使用这些模块。
21 3
|
1月前
|
JavaScript
Vue 开发技巧·1
【4月更文挑战第2天】通过props解耦Vue组件与路由参数,避免使用`$route`导致的高耦合。在路由配置中设定`props: true`,如`{ path: /user/:id, component: User, props: true }`,使组件能直接通过`props`获取`params`。此外,功能组件是无状态、不可实例化的,依赖外部数据且无生命周期,提高渲染性能。通过上下文参数传递所需数据,如`{{item.title}} {{item.content}}`,在父组件中定义并传递`list`数据。
30 8