Skip to content

Commit 0f9c846

Browse files
Refactor server.js and package.json for improved clarity and build process
1 parent 8a598ea commit 0f9c846

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

backend/server.js

+3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import { app, server } from "./socket/socket.js";
1212

1313
dotenv.config();
1414

15+
//
1516
const __dirname = path.resolve();
17+
1618
// PORT should be assigned after calling dotenv.config() because we need to access the env variables. Didn't realize while recording the video. Sorry for the confusion.
1719
const PORT = process.env.PORT || 3000;
1820

@@ -23,6 +25,7 @@ app.use("/api/auth", authRoutes);
2325
app.use("/api/messages", messageRoutes);
2426
app.use("/api/users", userRoutes);
2527

28+
//Its a middleware function, Serve the static files from the React app
2629
app.use(express.static(path.join(__dirname, "/frontend/dist")));
2730

2831
app.get("*", (req, res) => {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "1.0.0",
44
"main": "server.js",
55
"scripts": {
6-
"start": "node backend/server.js",
7-
"build": "cd frontend && npm install && npm run build",
86
"server": "nodemon backend/server.js",
7+
"start": "node backend/server.js",
8+
"build": "npm install && npm install --prefix frontend && npm run build --prefix frontend",
99
"dev": "concurrently \"npm run server\" \"cd frontend && npm run dev\""
1010
},
1111
"type": "module",

0 commit comments

Comments
 (0)