From 54f1c77cb5fd13e48b670d1f63a4b6ba50c34301 Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Fri, 19 Jun 2026 02:37:00 +0100 Subject: [PATCH 01/23] Setup backend project --- chat-app/backend/.gitignore | 1 + chat-app/backend/app.js | 0 chat-app/backend/package-lock.json | 884 +++++++++++++++++++++++++++++ chat-app/backend/package.json | 17 + 4 files changed, 902 insertions(+) create mode 100644 chat-app/backend/.gitignore create mode 100644 chat-app/backend/app.js create mode 100644 chat-app/backend/package-lock.json create mode 100644 chat-app/backend/package.json diff --git a/chat-app/backend/.gitignore b/chat-app/backend/.gitignore new file mode 100644 index 00000000..3c3629e6 --- /dev/null +++ b/chat-app/backend/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/chat-app/backend/app.js b/chat-app/backend/app.js new file mode 100644 index 00000000..e69de29b diff --git a/chat-app/backend/package-lock.json b/chat-app/backend/package-lock.json new file mode 100644 index 00000000..dba8276c --- /dev/null +++ b/chat-app/backend/package-lock.json @@ -0,0 +1,884 @@ +{ + "name": "backend", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "backend", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "cors": "^2.8.6", + "express": "^5.2.1" + } + }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/body-parser": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.3.0.tgz", + "integrity": "sha512-2cGmJupaNgg+QUwVLAucDuWuoMZ6EX9iHDRswZ5lsNYEmwPaRknMPCLZz07yTzVq/83p4o/wzbDZbBrTvGGTIw==", + "license": "MIT", + "dependencies": { + "bytes": "^3.1.2", + "content-type": "^2.0.0", + "debug": "^4.4.3", + "http-errors": "^2.0.1", + "iconv-lite": "^0.7.2", + "on-finished": "^2.4.1", + "qs": "^6.15.2", + "raw-body": "^3.0.2", + "type-is": "^2.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/body-parser/node_modules/content-type": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.0.0.tgz", + "integrity": "sha512-j/O/d7GcZCyNl7/hwZAb606rzqkyvaDctLmckbxLzHvFBzTJHuGEdodATcP3yIRoDrLHkIATJuvzbFlp/ki2cQ==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/content-disposition": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.1.0.tgz", + "integrity": "sha512-5jRCH9Z/+DRP7rkvY83B+yGIGX96OYdJmzngqnw2SBSxqCFPd0w2km3s5iawpGX8krnwSGmF0FW5Nhr0Hfai3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } + }, + "node_modules/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz", + "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz", + "integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.2.1", + "content-disposition": "^1.0.0", + "content-type": "^1.0.5", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "depd": "^2.0.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.7", + "qs": "^6.14.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.0.1", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/finalhandler": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz", + "integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", + "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz", + "integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", + "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/mime-db": { + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz", + "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", + "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz", + "integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.15.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.2.tgz", + "integrity": "sha512-Rzq0KEyX/w/tEybncDgdkZrJgVUsUMk3xjh3t5bv3S1HTAtg+uOYt72+ZfwiQwKdysThkTBdL/rTi6HDmX9Ddw==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", + "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.7.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", + "integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.1", + "mime-types": "^3.0.2", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/serve-static": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz", + "integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==", + "license": "MIT", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz", + "integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4", + "side-channel-list": "^1.0.1", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz", + "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.1.0.tgz", + "integrity": "sha512-faYHw0anBbc/kWF3zFTEnxSFOAGUX9GFbOBthvDdLsIlEoWOFOtS0zgCiQYwIskL9iGXZL3kAXD8OoZ4GmMATA==", + "license": "MIT", + "dependencies": { + "content-type": "^2.0.0", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/type-is/node_modules/content-type": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.0.0.tgz", + "integrity": "sha512-j/O/d7GcZCyNl7/hwZAb606rzqkyvaDctLmckbxLzHvFBzTJHuGEdodATcP3yIRoDrLHkIATJuvzbFlp/ki2cQ==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + } + } +} diff --git a/chat-app/backend/package.json b/chat-app/backend/package.json new file mode 100644 index 00000000..4c1000a0 --- /dev/null +++ b/chat-app/backend/package.json @@ -0,0 +1,17 @@ +{ + "name": "backend", + "version": "1.0.0", + "description": "", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "type": "commonjs", + "dependencies": { + "cors": "^2.8.6", + "express": "^5.2.1" + } +} From 26e8f49501c806ad186ff1cb86cd58afeaa9eeec Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Tue, 23 Jun 2026 15:47:31 +0100 Subject: [PATCH 02/23] nodemon, express installed, get, and post endpoint created --- chat-app/backend/app.js | 35 +++ chat-app/backend/package-lock.json | 352 +++++++++++++++++++++++++++++ chat-app/backend/package.json | 6 +- 3 files changed, 392 insertions(+), 1 deletion(-) diff --git a/chat-app/backend/app.js b/chat-app/backend/app.js index e69de29b..8d4a4946 100644 --- a/chat-app/backend/app.js +++ b/chat-app/backend/app.js @@ -0,0 +1,35 @@ +const express = require("express"); +const app = express(); +app.use(express.json()) + +const AllMessages = [ + { + name: "Saeid", + message: "Hi, How are you?" + }, +] + +const fetchAllMessages = () => { + return AllMessages +} + +app.get("/", (req, res) => { + const messages = fetchAllMessages() + res.json(messages) +}) + +app.post("/message", (req, res) => { + + const {message, name} = req.body + console.log(`Received message: ${name} ${message}`); + res.send({ + status: "success", + message: message, + name: name + }) + +}) + +app.listen("3000", () => { + console.log("server is running in this port") +}) diff --git a/chat-app/backend/package-lock.json b/chat-app/backend/package-lock.json index dba8276c..70b48771 100644 --- a/chat-app/backend/package-lock.json +++ b/chat-app/backend/package-lock.json @@ -11,6 +11,9 @@ "dependencies": { "cors": "^2.8.6", "express": "^5.2.1" + }, + "devDependencies": { + "nodemon": "^3.1.14" } }, "node_modules/accepts": { @@ -26,6 +29,43 @@ "node": ">= 0.6" } }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dev": true, + "license": "ISC", + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, + "node_modules/binary-extensions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", + "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/body-parser": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.3.0.tgz", @@ -63,6 +103,32 @@ "url": "https://opencollective.com/express" } }, + "node_modules/brace-expansion": { + "version": "5.0.6", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.6.tgz", + "integrity": "sha512-kLpxurY4Z4r9sgMsyG0Z9uzsBlgiU/EFKhj/h91/8yHu0edo7XuixOIH3VcJ8kkxs6/jPzoI6U9Vj3WqbMQ94g==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" + } + }, + "node_modules/braces": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fill-range": "^7.1.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -101,6 +167,31 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/chokidar": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "dev": true, + "license": "MIT", + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, "node_modules/content-disposition": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.1.0.tgz", @@ -301,6 +392,19 @@ "url": "https://opencollective.com/express" } }, + "node_modules/fill-range": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "dev": true, + "license": "MIT", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/finalhandler": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz", @@ -340,6 +444,21 @@ "node": ">= 0.8" } }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -386,6 +505,19 @@ "node": ">= 0.4" } }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/gopd": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", @@ -398,6 +530,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/has-symbols": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", @@ -458,6 +600,13 @@ "url": "https://opencollective.com/express" } }, + "node_modules/ignore-by-default": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", + "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==", + "dev": true, + "license": "ISC" + }, "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", @@ -473,6 +622,52 @@ "node": ">= 0.10" } }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "license": "MIT", + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.12.0" + } + }, "node_modules/is-promise": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", @@ -534,6 +729,22 @@ "url": "https://opencollective.com/express" } }, + "node_modules/minimatch": { + "version": "10.2.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.5.tgz", + "integrity": "sha512-MULkVLfKGYDFYejP07QOurDLLQpcjk7Fw+7jXS2R2czRQzR56yHRveU5NDJEOviH+hETZKSkIk5c+T23GjFUMg==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "brace-expansion": "^5.0.5" + }, + "engines": { + "node": "18 || 20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -549,6 +760,45 @@ "node": ">= 0.6" } }, + "node_modules/nodemon": { + "version": "3.1.14", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.14.tgz", + "integrity": "sha512-jakjZi93UtB3jHMWsXL68FXSAosbLfY0In5gtKq3niLSkrWznrVBzXFNOEMJUfc9+Ke7SHWoAZsiMkNP3vq6Jw==", + "dev": true, + "license": "MIT", + "dependencies": { + "chokidar": "^3.5.2", + "debug": "^4", + "ignore-by-default": "^1.0.1", + "minimatch": "^10.2.1", + "pstree.remy": "^1.1.8", + "semver": "^7.5.3", + "simple-update-notifier": "^2.0.0", + "supports-color": "^5.5.0", + "touch": "^3.1.0", + "undefsafe": "^2.0.5" + }, + "bin": { + "nodemon": "bin/nodemon.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nodemon" + } + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -610,6 +860,19 @@ "url": "https://opencollective.com/express" } }, + "node_modules/picomatch": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz", + "integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -623,6 +886,13 @@ "node": ">= 0.10" } }, + "node_modules/pstree.remy": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", + "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==", + "dev": true, + "license": "MIT" + }, "node_modules/qs": { "version": "6.15.2", "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.2.tgz", @@ -662,6 +932,19 @@ "node": ">= 0.10" } }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "license": "MIT", + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, "node_modules/router": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", @@ -684,6 +967,19 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "license": "MIT" }, + "node_modules/semver": { + "version": "7.8.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", + "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/send": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", @@ -807,6 +1103,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/simple-update-notifier": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", + "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", + "dev": true, + "license": "MIT", + "dependencies": { + "semver": "^7.5.3" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/statuses": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", @@ -816,6 +1125,32 @@ "node": ">= 0.8" } }, + "node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, "node_modules/toidentifier": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", @@ -825,6 +1160,16 @@ "node": ">=0.6" } }, + "node_modules/touch": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz", + "integrity": "sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==", + "dev": true, + "license": "ISC", + "bin": { + "nodetouch": "bin/nodetouch.js" + } + }, "node_modules/type-is": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.1.0.tgz", @@ -856,6 +1201,13 @@ "url": "https://opencollective.com/express" } }, + "node_modules/undefsafe": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", + "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", + "dev": true, + "license": "MIT" + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", diff --git a/chat-app/backend/package.json b/chat-app/backend/package.json index 4c1000a0..0dd5f01d 100644 --- a/chat-app/backend/package.json +++ b/chat-app/backend/package.json @@ -4,7 +4,8 @@ "description": "", "main": "app.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "dev": "nodemon index.js" }, "keywords": [], "author": "", @@ -13,5 +14,8 @@ "dependencies": { "cors": "^2.8.6", "express": "^5.2.1" + }, + "devDependencies": { + "nodemon": "^3.1.14" } } From f5d7cb9c786b40317a470fd6fe1a84de1522bfa7 Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Tue, 23 Jun 2026 16:07:38 +0100 Subject: [PATCH 03/23] saving messages with the same structure --- chat-app/backend/app.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/chat-app/backend/app.js b/chat-app/backend/app.js index 8d4a4946..b2a7eb49 100644 --- a/chat-app/backend/app.js +++ b/chat-app/backend/app.js @@ -2,7 +2,7 @@ const express = require("express"); const app = express(); app.use(express.json()) -const AllMessages = [ +const allMessages = [ { name: "Saeid", message: "Hi, How are you?" @@ -10,10 +10,10 @@ const AllMessages = [ ] const fetchAllMessages = () => { - return AllMessages + return allMessages } -app.get("/", (req, res) => { +app.get("/message", (req, res) => { const messages = fetchAllMessages() res.json(messages) }) @@ -22,6 +22,11 @@ app.post("/message", (req, res) => { const {message, name} = req.body console.log(`Received message: ${name} ${message}`); + allMessages.push({ + name: name, + message: message + }) + console.log(allMessages) res.send({ status: "success", message: message, From c7c5214844de5b447835eb8559bbacfe63b5d82c Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Tue, 23 Jun 2026 16:09:05 +0100 Subject: [PATCH 04/23] key , and val are same so allowed to name, message --- chat-app/backend/app.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/chat-app/backend/app.js b/chat-app/backend/app.js index b2a7eb49..53174128 100644 --- a/chat-app/backend/app.js +++ b/chat-app/backend/app.js @@ -23,8 +23,7 @@ app.post("/message", (req, res) => { const {message, name} = req.body console.log(`Received message: ${name} ${message}`); allMessages.push({ - name: name, - message: message + name,message }) console.log(allMessages) res.send({ From c88dbfdc5a0a82131b8cbca61948c8d8d885d08b Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Tue, 23 Jun 2026 18:35:18 +0100 Subject: [PATCH 05/23] Implement WebSocket server and broadcast messages to connected clients --- chat-app/backend/app.js | 90 +++++++++++++++++++++++++++++- chat-app/backend/package-lock.json | 24 +++++++- chat-app/backend/package.json | 3 +- 3 files changed, 113 insertions(+), 4 deletions(-) diff --git a/chat-app/backend/app.js b/chat-app/backend/app.js index 53174128..4e4b0e1d 100644 --- a/chat-app/backend/app.js +++ b/chat-app/backend/app.js @@ -1,3 +1,4 @@ +const WebSocket = require("ws"); const express = require("express"); const app = express(); app.use(express.json()) @@ -13,11 +14,12 @@ const fetchAllMessages = () => { return allMessages } -app.get("/message", (req, res) => { +app.get("/messages", (req, res) => { const messages = fetchAllMessages() res.json(messages) }) +const clients = []; app.post("/message", (req, res) => { const {message, name} = req.body @@ -26,6 +28,14 @@ app.post("/message", (req, res) => { name,message }) console.log(allMessages) + + clients.forEach(client =>{ + client.send(JSON.stringify({ + name, + message + })) + }) + res.send({ status: "success", message: message, @@ -34,6 +44,82 @@ app.post("/message", (req, res) => { }) -app.listen("3000", () => { +// app.listen("3000", () => { +// console.log("server is running in this port") +// }) +// Replace app.listen with http.createServer + + +//webSocket + +// we need to create a server manually +const http = require("http"); +const server = http.createServer(app); + +server.listen("3000", () => { console.log("server is running in this port") }) +//Then create the WebSocket server: +const wss = new WebSocket.Server({ server }); +/*✅ What this means +wss = your WebSocket server +It is connected to your HTTP server ✅ +It’s now ready to accept connections ✅ +*/ +wss.on("connection", (ws) => { + console.log("New client connected"); + clients.push(ws); + + ws.on("close", () => { + console.log("Client disconnected"); + const index = clients.indexOf(ws); + clients.splice(index, 1); + }); + +}); +//Each ws = one connected user +//You detect when a user connects ✅ +//But you don’t remember them ❌ + + + +//✅ STEP 3 — Store connected clients +// const clients = []; + +//✅ STEP 4 — Handle disconnections (VERY important) +/* ws.on("close", () => { + console.log("Client disconnected"); + + // remove this client from the array + const index = clients.indexOf(ws); + clients.splice(index, 1); + }); +✅ What this means (simple) + +ws.on("close") → runs when user leaves +indexOf(ws) → find that user +splice(...) → remove them + +✅ STEP 5 — Broadcast message to all clients +Right now: + +You store messages ✅ +You track connected users ✅ +But you don’t send messages to them yet ❌ +✅ Goal of this step +👉 When a new message is posted: + +Send it to every connected client instantly +clients.forEach((client) => { + client.send(JSON.stringify({ + name, + message + })); +}); +`` +JSON.stringify → convert object → text (required) +WebSockets only send strings, not objects + + +*/ + diff --git a/chat-app/backend/package-lock.json b/chat-app/backend/package-lock.json index 70b48771..19e06cbb 100644 --- a/chat-app/backend/package-lock.json +++ b/chat-app/backend/package-lock.json @@ -10,7 +10,8 @@ "license": "ISC", "dependencies": { "cors": "^2.8.6", - "express": "^5.2.1" + "express": "^5.2.1", + "ws": "^8.21.0" }, "devDependencies": { "nodemon": "^3.1.14" @@ -1231,6 +1232,27 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "license": "ISC" + }, + "node_modules/ws": { + "version": "8.21.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.21.0.tgz", + "integrity": "sha512-Vsp28b7DRcimFQvrqu2Wek3z1iYxDCWqHYB8Qsnk/S4RfaCQzPGPyBNuVjJV3cd6UiKtUtp6sNM77gWvzcCH+g==", + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } } } } diff --git a/chat-app/backend/package.json b/chat-app/backend/package.json index 0dd5f01d..684fedcd 100644 --- a/chat-app/backend/package.json +++ b/chat-app/backend/package.json @@ -13,7 +13,8 @@ "type": "commonjs", "dependencies": { "cors": "^2.8.6", - "express": "^5.2.1" + "express": "^5.2.1", + "ws": "^8.21.0" }, "devDependencies": { "nodemon": "^3.1.14" From f245b51d1b938ec9e872a5dfef0cb742b0a9810c Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Tue, 23 Jun 2026 18:45:51 +0100 Subject: [PATCH 06/23] add timestamp --- chat-app/backend/app.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/chat-app/backend/app.js b/chat-app/backend/app.js index 4e4b0e1d..d39187f5 100644 --- a/chat-app/backend/app.js +++ b/chat-app/backend/app.js @@ -1,14 +1,10 @@ const WebSocket = require("ws"); const express = require("express"); + const app = express(); app.use(express.json()) -const allMessages = [ - { - name: "Saeid", - message: "Hi, How are you?" - }, -] +const allMessages = [] const fetchAllMessages = () => { return allMessages @@ -23,16 +19,18 @@ const clients = []; app.post("/message", (req, res) => { const {message, name} = req.body + const timestamp = new Date(); console.log(`Received message: ${name} ${message}`); allMessages.push({ - name,message + name, message, timestamp }) console.log(allMessages) clients.forEach(client =>{ client.send(JSON.stringify({ name, - message + message, + timestamp })) }) @@ -54,6 +52,7 @@ app.post("/message", (req, res) => { // we need to create a server manually const http = require("http"); +const { time } = require("console"); const server = http.createServer(app); server.listen("3000", () => { From cfcaa1fa337736e22a54cbce80857520405b0273 Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Wed, 24 Jun 2026 12:00:37 +0100 Subject: [PATCH 07/23] i also add timestamp to the res, and deleted an unnecessary line --- chat-app/backend/app.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chat-app/backend/app.js b/chat-app/backend/app.js index d39187f5..ef6b37b1 100644 --- a/chat-app/backend/app.js +++ b/chat-app/backend/app.js @@ -37,7 +37,8 @@ app.post("/message", (req, res) => { res.send({ status: "success", message: message, - name: name + name: name, + timestamp: timestamp }) }) @@ -52,10 +53,9 @@ app.post("/message", (req, res) => { // we need to create a server manually const http = require("http"); -const { time } = require("console"); const server = http.createServer(app); -server.listen("3000", () => { +server.listen(3000, () => { console.log("server is running in this port") }) //Then create the WebSocket server: From 389432de1e224468f698dc9fea9ed03f611cfee0 Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Wed, 24 Jun 2026 12:31:14 +0100 Subject: [PATCH 08/23] fetching data from backend --- chat-app/frontend/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 chat-app/frontend/index.js diff --git a/chat-app/frontend/index.js b/chat-app/frontend/index.js new file mode 100644 index 00000000..5b130634 --- /dev/null +++ b/chat-app/frontend/index.js @@ -0,0 +1,16 @@ +// const message = document.getElementById("") +// const userName = document.getElementById("username") + +const fetchMessages = async () => { + const url = "http://localhost:3000/messages" + + try { + const response = await fetch(url); + const data = await response.json() + console.log(data) + } catch { + console.log("check the url") + } + +} +fetchMessages() \ No newline at end of file From 9072ec2f75f6026f2ba48c14908eda916366c987 Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Wed, 24 Jun 2026 12:36:33 +0100 Subject: [PATCH 09/23] cors installed and imported --- chat-app/backend/app.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/chat-app/backend/app.js b/chat-app/backend/app.js index ef6b37b1..6782ff6e 100644 --- a/chat-app/backend/app.js +++ b/chat-app/backend/app.js @@ -1,8 +1,11 @@ const WebSocket = require("ws"); const express = require("express"); +const cors = require('cors'); + const app = express(); app.use(express.json()) +app.use(cors()); const allMessages = [] @@ -18,15 +21,15 @@ app.get("/messages", (req, res) => { const clients = []; app.post("/message", (req, res) => { - const {message, name} = req.body + const { message, name } = req.body const timestamp = new Date(); console.log(`Received message: ${name} ${message}`); allMessages.push({ - name, message, timestamp + name, message, timestamp }) console.log(allMessages) - clients.forEach(client =>{ + clients.forEach(client => { client.send(JSON.stringify({ name, message, From f7a111aaf261653c5df5592a09aa5733b6516a9a Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Wed, 24 Jun 2026 14:47:45 +0100 Subject: [PATCH 10/23] fetching data from backend to frontend --- chat-app/frontend/index.html | 19 +++++++++++++++++++ chat-app/frontend/index.js | 30 +++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 chat-app/frontend/index.html diff --git a/chat-app/frontend/index.html b/chat-app/frontend/index.html new file mode 100644 index 00000000..9206a68d --- /dev/null +++ b/chat-app/frontend/index.html @@ -0,0 +1,19 @@ + + + + Chat App + + + +

chat here

+
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/chat-app/frontend/index.js b/chat-app/frontend/index.js index 5b130634..2553ba13 100644 --- a/chat-app/frontend/index.js +++ b/chat-app/frontend/index.js @@ -1,6 +1,3 @@ -// const message = document.getElementById("") -// const userName = document.getElementById("username") - const fetchMessages = async () => { const url = "http://localhost:3000/messages" @@ -8,9 +5,32 @@ const fetchMessages = async () => { const response = await fetch(url); const data = await response.json() console.log(data) + + const messages = document.getElementById("messages") + messages.innerHTML = ""; // avoid duplicatin when u need to call func again + + data.forEach((e) => { + const div = document.createElement("div") + + const userName = document.createElement("div") + userName.textContent = e.name + div.appendChild(userName) + + const message = document.createElement("p") + message.textContent = e.message + div.appendChild(message) + + const timestamp = document.createElement("span") + timestamp.textContent = e.timestamp + div.appendChild(timestamp) + + messages.appendChild(div) + } + ) } catch { console.log("check the url") } - } -fetchMessages() \ No newline at end of file + +fetchMessages() + From 25014c9ba06950fba7b1c02e07916bbc167a5c57 Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Wed, 24 Jun 2026 15:34:25 +0100 Subject: [PATCH 11/23] frontend can send message --- chat-app/frontend/index.html | 28 ++++++++++++++-------------- chat-app/frontend/index.js | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/chat-app/frontend/index.html b/chat-app/frontend/index.html index 9206a68d..ae47fe7e 100644 --- a/chat-app/frontend/index.html +++ b/chat-app/frontend/index.html @@ -1,19 +1,19 @@ - - Chat App - + + Chat App + - -

chat here

-
- -
- - -
- + +

chat here

+
- - +
+ + +
+ + + + \ No newline at end of file diff --git a/chat-app/frontend/index.js b/chat-app/frontend/index.js index 2553ba13..f8c25ef4 100644 --- a/chat-app/frontend/index.js +++ b/chat-app/frontend/index.js @@ -33,4 +33,22 @@ const fetchMessages = async () => { } fetchMessages() + // send a message + + const sendMessage = async () => { + const name = document.getElementById("user").value + const msg = document.getElementById("msg").value + const url = "http://localhost:3000/message" + + await fetch(url, { + method: "POST", + headers: { + "Content-Type" : "application/json", + }, + body: JSON.stringify({ + name : name, + message : msg + }) + }) + } From f2aa893af54b48bcc7d78091fdb50f4744333573 Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Wed, 24 Jun 2026 15:39:05 +0100 Subject: [PATCH 12/23] reload messages, and inputs clear --- chat-app/frontend/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/chat-app/frontend/index.js b/chat-app/frontend/index.js index f8c25ef4..c6693fac 100644 --- a/chat-app/frontend/index.js +++ b/chat-app/frontend/index.js @@ -50,5 +50,9 @@ fetchMessages() message : msg }) }) + + fetchMessages() + document.getElementById("user").value = "" + document.getElementById("msg").value = "" } From e260d790927a06478e0bdbe03b8f85eefb6d348b Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Wed, 24 Jun 2026 15:42:03 +0100 Subject: [PATCH 13/23] when key, and value are same u are alowed to do name in js --- chat-app/frontend/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chat-app/frontend/index.js b/chat-app/frontend/index.js index c6693fac..112b5a10 100644 --- a/chat-app/frontend/index.js +++ b/chat-app/frontend/index.js @@ -46,7 +46,7 @@ fetchMessages() "Content-Type" : "application/json", }, body: JSON.stringify({ - name : name, + name, message : msg }) }) From 77708794634ebb70a5210e8a4cc5de74c8a70843 Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Wed, 24 Jun 2026 16:16:04 +0100 Subject: [PATCH 14/23] websocket added to show messages instantly, and broadcasting --- chat-app/frontend/index.js | 39 +++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/chat-app/frontend/index.js b/chat-app/frontend/index.js index 112b5a10..df138501 100644 --- a/chat-app/frontend/index.js +++ b/chat-app/frontend/index.js @@ -33,26 +33,51 @@ const fetchMessages = async () => { } fetchMessages() - // send a message - const sendMessage = async () => { +const sendMessage = async () => { const name = document.getElementById("user").value const msg = document.getElementById("msg").value const url = "http://localhost:3000/message" - await fetch(url, { + await fetch(url, { method: "POST", headers: { - "Content-Type" : "application/json", + "Content-Type": "application/json", }, body: JSON.stringify({ name, - message : msg + message: msg }) }) - fetchMessages() + // fetchMessages() instead webSocket document.getElementById("user").value = "" document.getElementById("msg").value = "" - } +} + + +const ws = new WebSocket("ws://localhost:3000"); + +ws.onmessage = (event) => { + const data = JSON.parse(event.data); + console.log(data); + + const messages = document.getElementById("messages"); + + const div = document.createElement("div"); + + const nameEl = document.createElement("div"); + nameEl.textContent = data.name; + + const messageEl = document.createElement("p"); + messageEl.textContent = data.message; + + const timeEl = document.createElement("span"); + timeEl.textContent = data.timestamp; + + div.appendChild(nameEl); + div.appendChild(messageEl); + div.appendChild(timeEl); + messages.appendChild(div); +}; \ No newline at end of file From 34c512d47727cc9914784425e96556227d45363b Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Wed, 24 Jun 2026 17:25:07 +0100 Subject: [PATCH 15/23] changed tags name, and added a simple css --- chat-app/frontend/index.html | 11 ++++-- chat-app/frontend/index.js | 8 ++-- chat-app/frontend/style.css | 73 ++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 chat-app/frontend/style.css diff --git a/chat-app/frontend/index.html b/chat-app/frontend/index.html index ae47fe7e..8ab1e2e7 100644 --- a/chat-app/frontend/index.html +++ b/chat-app/frontend/index.html @@ -1,19 +1,22 @@ + Chat App + -

chat here

-
- +

Chat App

+
- + +
+ \ No newline at end of file diff --git a/chat-app/frontend/index.js b/chat-app/frontend/index.js index df138501..76ce7a5b 100644 --- a/chat-app/frontend/index.js +++ b/chat-app/frontend/index.js @@ -12,7 +12,7 @@ const fetchMessages = async () => { data.forEach((e) => { const div = document.createElement("div") - const userName = document.createElement("div") + const userName = document.createElement("strong") userName.textContent = e.name div.appendChild(userName) @@ -20,7 +20,7 @@ const fetchMessages = async () => { message.textContent = e.message div.appendChild(message) - const timestamp = document.createElement("span") + const timestamp = document.createElement("small") timestamp.textContent = e.timestamp div.appendChild(timestamp) @@ -66,13 +66,13 @@ ws.onmessage = (event) => { const div = document.createElement("div"); - const nameEl = document.createElement("div"); + const nameEl = document.createElement("strong"); nameEl.textContent = data.name; const messageEl = document.createElement("p"); messageEl.textContent = data.message; - const timeEl = document.createElement("span"); + const timeEl = document.createElement("small"); timeEl.textContent = data.timestamp; div.appendChild(nameEl); diff --git a/chat-app/frontend/style.css b/chat-app/frontend/style.css new file mode 100644 index 00000000..9d8e6c74 --- /dev/null +++ b/chat-app/frontend/style.css @@ -0,0 +1,73 @@ +#messages { + background-color: #eee; + gap: 5px; + padding: 10px; + max-width: 50%; + margin: 0 auto; +} + + +div { + display: flex; + flex-direction: column; + background-color: white; + border-radius: 5px; +} + +strong { + font-weight: bold; + color: black; + padding: 0 0 0 10px; +} + +p { + margin: 5px 0 0 10px; + align-items: center; + word-break: break-word; +} + +small { + font-size: 12px; + color: gray; + align-self: flex-end; + padding: 0 10px 0 0; +} + +#send-message { + display: flex; + flex-direction: row; + align-items: center; + gap: 5px; + padding: 10px; + margin: 10px auto; + max-width: 80%; + background-color: #eee; + border-radius: 10px; +} + +input { + width: 120px; + height: 35px; + border-radius: 10px; + border: 1px solid #ccc; + padding: 5px; +} + +textarea { + flex: 1; + height: 35px; + resize: none; + border-radius: 10px; + border: 1px solid #ccc; + padding: 6px; +} + +button { + height: 35px; + background-color: #25D366; + color: white; + border: none; + border-radius: 10px; + padding: 0 12px; + cursor: pointer; +} \ No newline at end of file From 9f87449000d47e5c1ea9cde190c6b64f99366c84 Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Wed, 24 Jun 2026 23:22:07 +0100 Subject: [PATCH 16/23] added validation --- chat-app/backend/app.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/chat-app/backend/app.js b/chat-app/backend/app.js index 6782ff6e..34d5a125 100644 --- a/chat-app/backend/app.js +++ b/chat-app/backend/app.js @@ -2,7 +2,6 @@ const WebSocket = require("ws"); const express = require("express"); const cors = require('cors'); - const app = express(); app.use(express.json()) app.use(cors()); @@ -19,9 +18,15 @@ app.get("/messages", (req, res) => { }) const clients = []; -app.post("/message", (req, res) => { +app.post("/message", (req, res) => { const { message, name } = req.body + + if(!message.trim() || !name.trim()){ + return res.status(400).json({ + error: "Name and message are required" + }) + } const timestamp = new Date(); console.log(`Received message: ${name} ${message}`); allMessages.push({ @@ -46,12 +51,6 @@ app.post("/message", (req, res) => { }) -// app.listen("3000", () => { -// console.log("server is running in this port") -// }) -// Replace app.listen with http.createServer - - //webSocket // we need to create a server manually From d9e903ba5a5c5cb9353ff9a1c1f4ed730127a168 Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Wed, 24 Jun 2026 23:22:29 +0100 Subject: [PATCH 17/23] added validation --- chat-app/frontend/index.html | 7 +++-- chat-app/frontend/index.js | 56 ++++++++++++++++++++++++++++++------ chat-app/frontend/style.css | 13 ++++++++- 3 files changed, 63 insertions(+), 13 deletions(-) diff --git a/chat-app/frontend/index.html b/chat-app/frontend/index.html index 8ab1e2e7..670b4efc 100644 --- a/chat-app/frontend/index.html +++ b/chat-app/frontend/index.html @@ -9,10 +9,11 @@

Chat App

- - - + + +
+

diff --git a/chat-app/frontend/index.js b/chat-app/frontend/index.js index 76ce7a5b..2c47f526 100644 --- a/chat-app/frontend/index.js +++ b/chat-app/frontend/index.js @@ -6,9 +6,19 @@ const fetchMessages = async () => { const data = await response.json() console.log(data) + const messages = document.getElementById("messages") messages.innerHTML = ""; // avoid duplicatin when u need to call func again + if (data.length === 0) { + const noData = document.createElement("div") + noData.textContent = "There is no chat yet ..." + noData.classList.add("empty") + + messages.appendChild(noData) + return; + } + data.forEach((e) => { const div = document.createElement("div") @@ -21,7 +31,10 @@ const fetchMessages = async () => { div.appendChild(message) const timestamp = document.createElement("small") - timestamp.textContent = e.timestamp + timestamp.textContent = new Date(e.timestamp).toLocaleTimeString([], { + hour: "2-digit", + minute: "2-digit" + }); div.appendChild(timestamp) messages.appendChild(div) @@ -35,11 +48,12 @@ const fetchMessages = async () => { fetchMessages() const sendMessage = async () => { - const name = document.getElementById("user").value - const msg = document.getElementById("msg").value + const name = document.getElementById("user").value.trim() + const msg = document.getElementById("msg").value.trim() + const url = "http://localhost:3000/message" - await fetch(url, { + const res = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json", @@ -50,20 +64,41 @@ const sendMessage = async () => { }) }) + let data; + try { + data = await res.json(); + } catch { + data = {}; + } + if (!res.ok) { + showError(data.error); + return; + } + + document.getElementById("error").textContent = ""; + // fetchMessages() instead webSocket document.getElementById("user").value = "" document.getElementById("msg").value = "" } - +const showError = (msg) => { + const errorEl = document.getElementById("error"); + errorEl.textContent = msg; + errorEl.style.color = "red"; +}; const ws = new WebSocket("ws://localhost:3000"); ws.onmessage = (event) => { const data = JSON.parse(event.data); - console.log(data); const messages = document.getElementById("messages"); + const empty = document.querySelector(".empty"); + if (empty) { + empty.remove(); + } + const div = document.createElement("div"); const nameEl = document.createElement("strong"); @@ -72,12 +107,15 @@ ws.onmessage = (event) => { const messageEl = document.createElement("p"); messageEl.textContent = data.message; - const timeEl = document.createElement("small"); - timeEl.textContent = data.timestamp; + const timestamp = document.createElement("small"); + timestamp.textContent = new Date(data.timestamp).toLocaleTimeString([], { + hour: "2-digit", + minute: "2-digit" + }); div.appendChild(nameEl); div.appendChild(messageEl); - div.appendChild(timeEl); + div.appendChild(timestamp); messages.appendChild(div); }; \ No newline at end of file diff --git a/chat-app/frontend/style.css b/chat-app/frontend/style.css index 9d8e6c74..720b48d4 100644 --- a/chat-app/frontend/style.css +++ b/chat-app/frontend/style.css @@ -6,7 +6,6 @@ margin: 0 auto; } - div { display: flex; flex-direction: column; @@ -70,4 +69,16 @@ button { border-radius: 10px; padding: 0 12px; cursor: pointer; +} + +.empty { + color: red; +} + +#error { + font-size: 14px; + color: red; + text-align: center; + margin: 5px 0; + height: 18px; } \ No newline at end of file From 28f4ebd7ab5522173d656f7b41b03b70313897a4 Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Wed, 24 Jun 2026 23:35:54 +0100 Subject: [PATCH 18/23] deleted dead code and comments --- chat-app/frontend/index.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/chat-app/frontend/index.js b/chat-app/frontend/index.js index 2c47f526..5cae76e9 100644 --- a/chat-app/frontend/index.js +++ b/chat-app/frontend/index.js @@ -4,11 +4,9 @@ const fetchMessages = async () => { try { const response = await fetch(url); const data = await response.json() - console.log(data) - const messages = document.getElementById("messages") - messages.innerHTML = ""; // avoid duplicatin when u need to call func again + messages.innerHTML = ""; if (data.length === 0) { const noData = document.createElement("div") @@ -35,8 +33,8 @@ const fetchMessages = async () => { hour: "2-digit", minute: "2-digit" }); - div.appendChild(timestamp) + div.appendChild(timestamp) messages.appendChild(div) } ) @@ -64,16 +62,16 @@ const sendMessage = async () => { }) }) - let data; - try { - data = await res.json(); - } catch { - data = {}; - } - if (!res.ok) { - showError(data.error); - return; - } + let data; + try { + data = await res.json(); + } catch { + data = {}; + } + if (!res.ok) { + showError(data.error); + return; + } document.getElementById("error").textContent = ""; @@ -81,6 +79,7 @@ const sendMessage = async () => { document.getElementById("user").value = "" document.getElementById("msg").value = "" } + const showError = (msg) => { const errorEl = document.getElementById("error"); errorEl.textContent = msg; From b2ff7a99476e24c42ce0cdef7c768dd86e2b8aba Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Wed, 24 Jun 2026 23:36:39 +0100 Subject: [PATCH 19/23] deleted comment to be ready to deploy --- chat-app/backend/app.js | 59 +++-------------------------------------- 1 file changed, 4 insertions(+), 55 deletions(-) diff --git a/chat-app/backend/app.js b/chat-app/backend/app.js index 34d5a125..56fb7d6f 100644 --- a/chat-app/backend/app.js +++ b/chat-app/backend/app.js @@ -22,7 +22,7 @@ const clients = []; app.post("/message", (req, res) => { const { message, name } = req.body - if(!message.trim() || !name.trim()){ + if (!message.trim() || !name.trim()) { return res.status(400).json({ error: "Name and message are required" }) @@ -53,20 +53,15 @@ app.post("/message", (req, res) => { //webSocket -// we need to create a server manually const http = require("http"); const server = http.createServer(app); server.listen(3000, () => { console.log("server is running in this port") }) -//Then create the WebSocket server: + const wss = new WebSocket.Server({ server }); -/*✅ What this means -wss = your WebSocket server -It is connected to your HTTP server ✅ -It’s now ready to accept connections ✅ -*/ + wss.on("connection", (ws) => { console.log("New client connected"); clients.push(ws); @@ -77,50 +72,4 @@ wss.on("connection", (ws) => { clients.splice(index, 1); }); -}); -//Each ws = one connected user -//You detect when a user connects ✅ -//But you don’t remember them ❌ - - - -//✅ STEP 3 — Store connected clients -// const clients = []; - -//✅ STEP 4 — Handle disconnections (VERY important) -/* ws.on("close", () => { - console.log("Client disconnected"); - - // remove this client from the array - const index = clients.indexOf(ws); - clients.splice(index, 1); - }); -✅ What this means (simple) - -ws.on("close") → runs when user leaves -indexOf(ws) → find that user -splice(...) → remove them - -✅ STEP 5 — Broadcast message to all clients -Right now: - -You store messages ✅ -You track connected users ✅ -But you don’t send messages to them yet ❌ -✅ Goal of this step -👉 When a new message is posted: - -Send it to every connected client instantly -clients.forEach((client) => { - client.send(JSON.stringify({ - name, - message - })); -}); -`` -JSON.stringify → convert object → text (required) -WebSockets only send strings, not objects - - -*/ - +}); \ No newline at end of file From 3259f338bf58845f9c2c78a3de661fbbce1d8c3b Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Thu, 25 Jun 2026 00:29:44 +0100 Subject: [PATCH 20/23] Dockerfile added, start added to package, and const Port --- chat-app/backend/Dockerfile | 20 ++++++++++++++++++++ chat-app/backend/app.js | 9 ++++++--- chat-app/backend/package.json | 5 +++-- 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 chat-app/backend/Dockerfile diff --git a/chat-app/backend/Dockerfile b/chat-app/backend/Dockerfile new file mode 100644 index 00000000..212b19d0 --- /dev/null +++ b/chat-app/backend/Dockerfile @@ -0,0 +1,20 @@ +# Use Node +FROM node:18 + +# Create app folder +WORKDIR /app + +# Copy package files +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Copy all files +COPY . . + +# Expose port +EXPOSE 3000 + +# Start server +CMD ["node", "app.js"] \ No newline at end of file diff --git a/chat-app/backend/app.js b/chat-app/backend/app.js index 56fb7d6f..aab173a9 100644 --- a/chat-app/backend/app.js +++ b/chat-app/backend/app.js @@ -56,9 +56,12 @@ app.post("/message", (req, res) => { const http = require("http"); const server = http.createServer(app); -server.listen(3000, () => { - console.log("server is running in this port") -}) +const PORT = process.env.PORT || 3000; + +server.listen(PORT, () => { + console.log("server is running"); +}); + const wss = new WebSocket.Server({ server }); diff --git a/chat-app/backend/package.json b/chat-app/backend/package.json index 684fedcd..442ae975 100644 --- a/chat-app/backend/package.json +++ b/chat-app/backend/package.json @@ -5,7 +5,8 @@ "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "dev": "nodemon index.js" + "start": "node app.js", + "dev": "nodemon app.js" }, "keywords": [], "author": "", @@ -19,4 +20,4 @@ "devDependencies": { "nodemon": "^3.1.14" } -} +} \ No newline at end of file From d285aa0018f65bbb2cc470bc09e2a80f4436b7d8 Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Thu, 25 Jun 2026 01:19:56 +0100 Subject: [PATCH 21/23] port updated --- chat-app/backend/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chat-app/backend/app.js b/chat-app/backend/app.js index aab173a9..87d2587a 100644 --- a/chat-app/backend/app.js +++ b/chat-app/backend/app.js @@ -58,7 +58,7 @@ const server = http.createServer(app); const PORT = process.env.PORT || 3000; -server.listen(PORT, () => { +server.listen(PORT, "0.0.0.0", () => { console.log("server is running"); }); From f87b360144191ef58c718f88e89482c9fbed4bec Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Thu, 25 Jun 2026 01:39:02 +0100 Subject: [PATCH 22/23] updated urls --- chat-app/backend/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chat-app/backend/app.js b/chat-app/backend/app.js index 87d2587a..aab173a9 100644 --- a/chat-app/backend/app.js +++ b/chat-app/backend/app.js @@ -58,7 +58,7 @@ const server = http.createServer(app); const PORT = process.env.PORT || 3000; -server.listen(PORT, "0.0.0.0", () => { +server.listen(PORT, () => { console.log("server is running"); }); From 0bbd61d92ee4afd706c843fde6e91bdb40d9da2e Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Thu, 25 Jun 2026 01:39:41 +0100 Subject: [PATCH 23/23] updated urls --- chat-app/frontend/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chat-app/frontend/index.js b/chat-app/frontend/index.js index 5cae76e9..0a930c81 100644 --- a/chat-app/frontend/index.js +++ b/chat-app/frontend/index.js @@ -1,5 +1,5 @@ const fetchMessages = async () => { - const url = "http://localhost:3000/messages" + const url = "https://pp3psp4mxrlip4uxvmeb9cmv.hosting.codeyourfuture.io/messages" try { const response = await fetch(url); @@ -49,7 +49,7 @@ const sendMessage = async () => { const name = document.getElementById("user").value.trim() const msg = document.getElementById("msg").value.trim() - const url = "http://localhost:3000/message" + const url = "https://pp3psp4mxrlip4uxvmeb9cmv.hosting.codeyourfuture.io/message" const res = await fetch(url, { method: "POST", @@ -86,8 +86,8 @@ const showError = (msg) => { errorEl.style.color = "red"; }; -const ws = new WebSocket("ws://localhost:3000"); - +const ws = new +WebSocket("wss://pp3psp4mxrlip4uxvmeb9cmv.hosting.codeyourfuture.io"); ws.onmessage = (event) => { const data = JSON.parse(event.data);