1 Star 0 Fork 0

7sings/express-demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
7sings 提交于 2021-10-08 19:25 . feat: finish the demo
const express = require("express");
const app = express();
const http = require("http");
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);
const db = require("./models");
const userRouter = require("./routers/userRouter");
const dotenv = require("dotenv");
dotenv.config();
io.on("connection", (socket) => {
console.log(socket.id);
socket.on("message", ({ msg, username }) => {
console.log(`message from ${username}: ${msg}`);
io.send({ msg, username });
});
});
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use("/api/user", userRouter);
app.get("/", (req, res) => {
res.sendFile(__dirname + "/public/index.html");
});
(async () => {
try {
await db.sequelize.sync({ alter: true });
console.log("Database has synced.");
} catch (error) {
console.error("Unable to sync the database:", error);
}
})();
const { PORT } = process.env;
server.listen(PORT, () => {
console.log("Server has started on Port " + PORT);
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/rockwu_admin/express-demo.git
[email protected]:rockwu_admin/express-demo.git
rockwu_admin
express-demo
express-demo
master

搜索帮助