tarea german santiago

This commit is contained in:
santiage 2022-09-06 15:46:34 -06:00
parent b5628e1a35
commit 44988f110f
5 changed files with 1587 additions and 0 deletions

View File

@ -0,0 +1,13 @@
FROM node:18
#creamos un directorio para codigo js
RUN mkdir -p /home/app
#copiamos codigo a directorio
COPY . /home/app
#exponemos puesto
EXPOSE 3000
# ejecutamos comando para levantar servicio node
CMD ["node", "/home/app/index.js"]

View File

@ -0,0 +1,19 @@
version: "1.0"
services:
aplicacion:
build: .
ports:
- "3000:3000"
links:
- bdatos
bdatos:
image: mongo
ports:
- "27017:27017"
environment:
- MONGO_INITDB_ROOT_USERNAME=santiage
- MONGO_INITDB_ROOT_PASSWORD=santiagepass

View File

@ -0,0 +1,25 @@
import express from 'express'
import mongoose from 'mongoose'
const Animal = mongoose.model('Animal', new mongoose.Schema({
tipo: String,
estado: String,
}))
const app = express()
mongoose.connect('mongodb://santiage:santiagepass@bdatos:27017/miapp?authSource=admin')
app.get('/', async (_req, res) => {
console.log('listando... base de datos...')
const animales = await Animal.find();
return res.send(animales)
})
app.get('/crear/:pTipo', async (_req, res) => {
console.log('creando...')
await Animal.create({ tipo: _req.params.pTipo, estado: 'estado' })
return res.send('ok')
})
app.listen(3000, () => console.log('escuchando ...'))

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,16 @@
{
"name": "mongoapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.1",
"mongoose": "6.4.1"
}
}