{"size": 893, "ext": "js", "max_stars_repo_path": "day2/2-websoket/app.js", "max_stars_repo_name": "meseven/node-egitimi-bilgeadam", "max_stars_repo_stars_event_min_datetime": "2020-03-16T11:10:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-12T14:35:34.000Z", "max_issues_repo_path": "day2/2-websoket/app.js", "max_issues_repo_name": "meseven/node-egitimi-bilgeadam", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "day2/2-websoket/app.js", "max_forks_repo_name": "meseven/node-egitimi-bilgeadam", "max_forks_repo_forks_event_min_datetime": "2020-03-17T10:08:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-30T19:22:30.000Z"}
{"max_stars_count": 8, "max_issues_count": null, "max_forks_count": 3, "avg_line_length": 17.86, "max_line_length": 45, "alphanum_fraction": 0.6215005599}
const express = require("express");

const app = express();
app.use(express.static("public"));

const server = require("http").Server(app);
const io = require("socket.io")(server);

server.listen(80);

let userCount = 0;

io.on("connection", function(socket) {
	userCount++;

	io.emit("userCount", userCount);

	socket.on("newUser", data => {
		socket.broadcast.emit("newUser", data);
	});

	socket.on("changeColor", data => {
		socket.broadcast.emit("changeColor", data);
	});

	socket.on("disconnect", data => {
		userCount--;
		io.emit("userCount", userCount);
		console.log("a user disconnected");
	});
});

app.set("view engine", "pug");

app.get("/", (req, res) => {
	res.render("index");
});

app.get("/colors", (req, res) => {
	res.render("colors");
});

app.get("/counter", (req, res) => {
	res.render("counter");
});

app.listen(3000, err => {
	console.log("Server is running");
});
