-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
38 lines (29 loc) · 873 Bytes
/
app.js
File metadata and controls
38 lines (29 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const express = require('express');
const app=express();
const http=require('http').createServer(app);
const io=require('socket.io')(http);
const path=require('path');
// let templatepath=path.join(__dirname,"/view");
let staticpath=path.join(__dirname,"/public");
// app.set('view engine','hbs')
app.use(express.static(staticpath));
const PORT=process.env.PORT||'8000';
const hostname='127.0.0.1';
app.get("/",(req,res)=>{
res.sendFile(__dirname+"/index.html");
}
);
// app.get("/chatbox",(req,res)=>{
// res.render("chatbox");
// })
io.on('connection',(socket)=>{
// console.log("hello peoples..");
socket.on('msg_event',(msg)=>{
// console.log(msg);
socket.broadcast.emit('msg_event',msg)
})
})
console.log(__dirname);
http.listen(PORT,hostname,()=>{
console.log(`server listening on port http://${hostname}:${PORT}`);
})