Skip to content

Instantly share code, notes, and snippets.

View thekbbohara's full-sized avatar

Kb Bohara thekbbohara

View GitHub Profile
@thekbbohara
thekbbohara / socket.io.ts
Last active January 22, 2025 05:49
service.socket.io.ts
import { Server, type Socket } from "socket.io";
class SocketService {
private static instance: SocketService;
private _io: Server;
private _sockets: Record<string, Socket> = {}; // Store sockets by user ID
private constructor() {
console.log("Initializing Socket Service...");
this._io = new Server({
@thekbbohara
thekbbohara / qvsp
Last active December 21, 2024 18:23
qvsp
"use client";
import { useEffect, useRef } from "react";
import { io, type Socket } from "socket.io-client";
export const useSocket = (): Socket => {
const socketRef = useRef<Socket>();
if (!socketRef.current) {
socketRef.current = io("ws://ws.thekbbohara.xyz");

Node.js Deployment

Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Create Free AWS Account

Create free AWS Account at https://aws.amazon.com/

2. Create and Lauch an EC2 instance and SSH into machine

I would be creating a t2.medium ubuntu machine for this demo.

export const getSrcDir = async (cwd: string): Promise<string> => {
cwd = cwd || process.cwd();
const files = await readdir(cwd);
if (files.includes("src")) return resolve(cwd, "src");
if (files.includes("package.json")) {
await mkdir(resolve(cwd, "src"));
return resolve(cwd, "src");
}
return await getSrcDir(resolve(cwd, ".."));
};