Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt
Create free AWS Account at https://aws.amazon.com/
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, "..")); | |
| }; |
Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt
Create free AWS Account at https://aws.amazon.com/
I would be creating a t2.medium ubuntu machine for this demo.
| "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"); |
| 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({ |