Skip to content

Commit

Permalink
test node in server
Browse files Browse the repository at this point in the history
  • Loading branch information
gricn committed Mar 2, 2020
1 parent 5fdc4e4 commit 944a90d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:12.16
COPY \node\package.json /home/node/app/



19 changes: 12 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
version: "3"
services:
node:
image: node:13.8
image: node:12.16
user: "node"
build: .
working_dir: /home/node/app
environment:
- NODE_ENV=production
volumes:
- ./node/.:/home/node/app
depends_on:
- db
# volumes:
# - ./node:/home/node/app
expose:
- "8888"
command: "npm start"
command: bash -c
"npm install
&& npm start"
db:
image: postgres:12.2
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
depends_on:
- node
volumes:
- ./pgdata:/home/postgres/postgresql/data
ports:
- '5432:5432'
- '5432:5432'
expose:
- "5432"
3 changes: 2 additions & 1 deletion node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { Client } = require('pg');
const client = new Client({
user: "postgres",
password: "postgres",
host: "localhost",
host: "db",
port: 5432,
database: "postgres",
})
Expand All @@ -13,6 +13,7 @@ async function execute() {
try {
await client.connect()
console.log("connect successfully")
await client.query("create table ")
const results = await client.query("select * from test")
console.table(results.rows)
await client.end()
Expand Down

0 comments on commit 944a90d

Please sign in to comment.