first commit

This commit is contained in:
2025-11-26 07:12:51 +00:00
commit 3e43db51d3
7 changed files with 98 additions and 0 deletions

1
.env Normal file
View File

@@ -0,0 +1 @@
PORT=4000

24
Dockerfile Normal file
View File

@@ -0,0 +1,24 @@
FROM node:22.14.0-alpine AS builder
# Set working directory
WORKDIR /app
# Salin package.json dan package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm install
# Salin semua file source code
COPY . .
# (Opsional) Jalankan sebagai non-root user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
# Ekspos port
EXPOSE 4000
# Perintah untuk menjalankan aplikasi
CMD [ "node", "src/server.js" ]

24
docker-compose.yml Normal file
View File

@@ -0,0 +1,24 @@
# docker-compose.yml
version: '3.8'
services:
# Service untuk aplikasi Node.js
app:
container_name: express-test
# Build image dari Dockerfile di direktori saat ini
build:
context: .
dockerfile: Dockerfile
# Port mapping: <port-host>:<port-container>
ports:
- "4000:4000"
# Variabel lingkungan yang dibutuhkan oleh aplikasi
environment:
- PORT=4000
- DB_HOST=database
- DB_PORT=5432
- DB_USER=postgres
- DB_PASSWORD=postgres_password
- DB_NAME=tododb
# Restart policy
restart: unless-stopped

13
package-lock.json generated Normal file
View File

@@ -0,0 +1,13 @@
{
"name": "express",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "express",
"version": "1.0.0",
"license": "ISC"
}
}
}

14
package.json Normal file
View File

@@ -0,0 +1,14 @@
{
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node src/server.js",
"dev": "nodemon src/server.js"
},
"name": "express",
"version": "1.0.0",
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}

0
src/db/connection.js Normal file
View File

22
src/server.js Normal file
View File

@@ -0,0 +1,22 @@
// src/server.js
require('dotenv').config();
const express = require('express');
const app = express();
const PORT = process.env.PORT || 4000;
// Middleware
app.use(express.json()); // Untuk parsing application/json
// Routes
app.use('/todos', todoRoutes);
// Root endpoint
app.get('/', (req, res) => {
res.json({ message: 'Welcome to the BACEND Todo API!' });
});
// Start server
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});