Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nazar Tymiv #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/go/build-context-dockerignore/

**/.classpath
**/.dockerignore
# **/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.next
**/.cache
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
**/build
**/dist
LICENSE
README.md
8 changes: 4 additions & 4 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
HOST="Hostname_POSTGres_Container"
HOST="db"
PORT=5432
DATABASE="Example_DatabaseName"
USER="example_user"
PASSWORD="example_password"
DATABASE="Books"
USER="admin"
PASSWORD="123123"
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:20.11.1-alpine

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "start"]
22 changes: 22 additions & 0 deletions README.Docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Building and running your application

When you're ready, start your application by running:
`docker compose up --build`.

Your application will be available at http://localhost:4000.

### Deploying your application to the cloud

First, build your image, e.g.: `docker build -t myapp .`.
If your cloud uses a different CPU architecture than your development
machine (e.g., you are on a Mac M1 and your cloud provider is amd64),
you'll want to build the image for that platform, e.g.:
`docker build --platform=linux/amd64 -t myapp .`.

Then, push it to your registry, e.g. `docker push myregistry.com/myapp`.

Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/)
docs for more detail on building and pushing.

### References
* [Docker's Node.js guide](https://docs.docker.com/language/nodejs/)
Binary file added assets/docker-desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/response-in-cmd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/response.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.8'

services:
db:
image: postgres
environment:
POSTGRES_PASSWORD: 123123
POSTGRES_USER: admin
ports:
- '5432:5432'
volumes:
- /d/Docker/DB:/var/lib/postgresql/data

api:
image: docker-compose-challenge
ports:
- '3000:3000'
8 changes: 4 additions & 4 deletions db/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Load our .env file
require('dotenv').config()
// Require Client obj from the postgres node module
const { Client } = require("pg");
const {Client} = require('pg')

const client = {
query: async (str, values) => {
Expand All @@ -10,7 +10,7 @@ const client = {
port: process.env.PORT,
database: process.env.DATABASE,
user: process.env.USER,
password: process.env.PASSWORD
password: process.env.PASSWORD,
})
// connect a connection
await dbClient.connect()
Expand All @@ -19,7 +19,7 @@ const client = {
// close the connection
await dbClient.end()
return result
}
},
}

module.exports = client;
module.exports = client
20 changes: 9 additions & 11 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
const express = require("express");
const morgan = require("morgan");
const cors = require("cors");
const express = require('express')
const morgan = require('morgan')
const cors = require('cors')

const app = express();
const app = express()

app.use(morgan("dev"));
app.use(cors());
app.use(express.json());
app.use(morgan('dev'))
app.use(cors())
app.use(express.json())

//TODO: Implement books and pets APIs using Express Modular Routers
const booksRouter = require('./routers/books.js')
const petsRouter = require('./routers/pets.js')
// const petsRouter = require('./routers/pets.js')

app.use('/books', booksRouter)
app.use('/pets', petsRouter)


// app.use('/pets', petsRouter)

module.exports = app