Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
node_modules

10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{js,json,yml}]
charset = utf-8
indent_style = space
indent_size = 2
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.yarn/** linguist-vendored
/.yarn/releases/* binary
/.yarn/plugins/**/* binary
/.pnp.* binary linguist-generated
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,16 @@ CLAUDE.md
hermeto-output/
hermeto.env

.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Swap the comments on the following lines if you wish to use zero-installs
# In that case, don't forget to run `yarn config set enableGlobalCache false`!
# Documentation here: https://yarnpkg.com/features/caching#zero-installs

#!.yarn/cache
.pnp.*
Empty file added .yarnrc.yml
Empty file.
11 changes: 11 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM docker.io/node:20

COPY . /src

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve Docker build performance, it's better to copy only package.json, yarn.lock and the .yarn directory first, run yarn install, and then copy the rest of the application source code. This allows Docker to cache the dependencies layer and avoid reinstalling them on every code change. For example:

WORKDIR /src
COPY package.json yarn.lock ./
COPY .yarn ./.yarn
RUN yarn install
COPY . .

WORKDIR /src

RUN yarn install

EXPOSE 9000

CMD ["yarn", "run", "start"]

12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Repo of examples for Hermeto docs
# Sample NodeJS App

Individual examples each live in their own branch (e.g. the basic `pip` example is in
the 'pip-basic' branch)
This is a simple web application based on [Express](https://expressjs.com) used to test container
builds that rely on the yarn ecossystem.

## How to run it
```
yarn install
yarn start
```

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The file should end with a newline. The .editorconfig file specifies insert_final_newline = true for all files.

8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const express = require("express");

const port = 9000;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Hardcoding the port number makes the application less flexible. It's a good practice to read the port from an environment variable (e.g., process.env.PORT) and provide a default value if the environment variable is not set. This makes it easier to run the application in different environments, especially in containers.

Suggested change
const port = 9000;
const port = process.env.PORT || 9000;

const app = express();

app.get("/", (req, res) => res.send("Hello world!"));

app.listen(port, () => console.log(`App started on port ${port}...`));
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "yarn-basic-example",
"packageManager": "yarn@3.6.2",
"version": "1.0.0",
"description": "A sample NodeJS app",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current test script indicates that no tests are specified. Even for a sample application, including a basic test suite (e.g., using Jest or Mocha) would be a great addition to demonstrate best practices and ensure the application works as expected.

},
"author": "",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The author field is empty. It's good practice to specify the author of the package.

"license": "ISC",
"dependencies": {
"express": "^4.18.2"
}
}
Loading