📝 Added sandbox (code sketchbook)

This commit is contained in:
z3rOR0ne 2023-04-22 00:41:54 -07:00
parent b475595f7f
commit b5daf18b1a
142 changed files with 100702 additions and 0 deletions

View file

@ -0,0 +1,2 @@
node_modules
npm-debug.log

View file

@ -0,0 +1,6 @@
trailingComma: "all"
tabWidth: 4
semi: false
singleQuote: true
bracketSpacing: true
arrowParens: "avoid"

View file

@ -0,0 +1,19 @@
FROM node:18
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both apckage.json AND package-lock.json are
# copied where available (npm@5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm ci --omit=dev
# BUNDLE app source
COPY . .
EXPOSE 8080
CMD ["node", "server.js"]

View file

@ -0,0 +1,41 @@
## Basic Docker Usage with Node/Express backend
This small project was taken from an article over at [nodejs.org](https://nodejs.org/en/docs/guides/nodejs-docker-webapp).
### Of Note:
Ensure that you have a .dockerignore file so that you don't copy your
node_modules to the docker image:
```
node_modules
npm-debug.log
```
### Build, run, test:
```
docker build . -t <your username>/node-web-app
```
```
docker run -p 49160:8080 -d <your username>/node-web-app
```
Note that this is exposing docker's port 8080 to the host machine's port 49160
in this case, so after running the image you can visit it on your host machine
by going to localhost:49160, or for something this simple you can just use curl:
```
curl -i localhost:49160
```
If you want to go inside the container to check out the inside:
```
docker exec -it <container id> /bin/bash
```
### Further Reading:
[Building Efficient Dockerfiles - Node.js](https://bitjudo.com/blog/2014/03/13/building-efficient-dockerfiles-node-dot-js/)
[Introducing `npm ci` for faster, more reliable builds](https://blog.npmjs.org/post/171556855892/introducing-npm-ci-for-faster-more-reliable)

1018
sandbox/docker_web_app/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,16 @@
{
"name": "docker_web_app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2"
}
}

View file

@ -0,0 +1,15 @@
'use strict'
const express = require('express')
// Constants
const PORT = 8080
// App
const app = express()
app.get('/', (req, res) => {
res.send('Hello World')
})
app.listen(PORT, () => {
console.log(`Running on port: ${PORT}`)
})