# Use Node.js 18 base image
FROM node:18-slim
# Create app directory
WORKDIR /usr/src/app
# Install dependencies
COPY package.json package-lock.json ./
RUN npm install
# Copy source
COPY . .
# Build if a build script is provided
RUN npm run build --if-present
# Default command: perform a quick runtime check of the library
CMD ["node", "-e", "const m=require('./lib'); console.log('passport-jwt loaded:', typeof m.Strategy, typeof m.ExtractJwt);"]
Concerns: COPY package-lock.json may fail if the lockfile is not present in the repository, The CMD assumes the built library is available at ./lib (lib/index.js); if the build outputs elsewhere (e.g., dist/), the runtime check may fail
Smoke [FAIL]: node -e \"const m=require('./lib'); console.log('passport-jwt loaded:', typeof m.Strategy, typeof m.ExtractJwt);\
Output: sh: 1: Syntax error: "(" unexpected
Smoke [FAIL]: test -f lib/index.js && echo 'lib/index.js exists' || echo 'lib/index.js missing
Output: sh: 1: Syntax error: Unterminated quoted string# Use Node.js 18 base image
FROM node:18-slim
# Create app directory
WORKDIR /usr/src/app
# Install dependencies (only runtime dependencies for the library)
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
# Copy source
COPY . .
# Build if a build script is provided
RUN npm run build --if-present
# Create a tiny runtime check script to verify the library loads
RUN bash -lc 'cat > /usr/src/app/test-run.js << "JS"
const m = require("./lib");
console.log("passport-jwt loaded:", typeof m.Strategy, typeof m.ExtractJwt);
JS'
# Default command: run the test script to verify working container
CMD ["node", "/usr/src/app/test-run.js"]
node_modules dist build coverage .vscode .idea .git
#0 building with "default" instance using docker driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 690B done
#1 DONE 0.0s
Dockerfile:19
--------------------
17 | # Create a tiny runtime check script to verify the library loads
18 | RUN bash -lc 'cat > /usr/src/app/test-run.js << "JS"
19 | >>> const m = require("./lib");
20 | console.log("passport-jwt loaded:", typeof m.Strategy, typeof m.ExtractJwt);
21 | JS'
--------------------
ERROR: failed to build: failed to solve: dockerfile parse error on line 19: unknown instruction: const# Use Node.js 18 base image FROM node:18-slim # Create app directory WORKDIR /usr/src/app # Install dependencies COPY package.json package-lock.json ./ RUN npm ci # Copy source COPY . . # Build if a build script is provided RUN npm run build --if-present # Default command: run a quick test to verify library loads CMD ["node", "test-run.js"]
{
"name": "passport-jwt",
"version": "4.0.1",
"description": "Passport authentication strategy using JSON Web Tokens",
"main": "./lib",
"scripts": {
"test": "./node_modules/.bin/mocha --reporter spec --require test/bootstrap test/*test.js",
"testcov": "nyc npm run test"
},
"repository": {
"type": "git",
"url": "https://github.com/mikenicholson/passport-jwt.git"
},
"keywords": [
"Passport",
"Strategy",
"JSON",
"Web",
"Token",
"JWT"
],
"author": "Mike Nicholson",
"license": "MIT",
"bugs": {
"url": "https://github.com/mikenicholson/passport-jwt/issues"
},
"homepage": "https://github.com/mikenicholson/passport-jwt",
"devDependencies": {
"chai": "^3.0.0",
"chai-passport-strategy": "^1.0.0",
"mocha": "^9.2.1",
"nyc": "^15.1.0",
"sinon": "^1.0.0"
},
"dependencies": {
"jsonwebtoken": "^9.0.0",
"passport-strategy": "^1.0.0"
}
}
var chai = require('chai');
chai.use(require('chai-passport-strategy'));
global.expect = chai.expect;
Concerns: Depends on package-lock.json existing for npm ci; if lockfile is missing or out of sync, the build will fail., CMD relies on test-run.js being present at build time; if it's missing, the container will fail to start.
Smoke [FAIL]: node -e "try { require('./'); console.log('library loaded'); } catch (e) { console.error(e); process.exit(1); }
Output: sh: 1: Syntax error: Unterminated quoted string
Smoke [FAIL]: node test-run.js
Output: node:internal/modules/cjs/loader:1143
throw err;
^
Error: Cannot find module '/usr/src/app/test-run.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
at Module._load (node:internal/modules/cjs/loader:981:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v18.20.8const m = require('./lib');
console.log('passport-jwt loaded:', typeof m.Strategy, typeof m.ExtractJwt);
Concerns: The CMD assumes test-run.js exists and runs a library smoke test; if the file is not present, container will fail at runtime., If the library has native addons, npm ci may require build tools not present in node:18-slim; consider installing build-essential or similar if needed., COPY . . may copy unnecessary files; ensure a .dockerignore is configured to avoid shipping large or sensitive files.
Smoke [FAIL]: node -e "require('./'); console.log('library loaded')
Output: sh: 1: Syntax error: Unterminated quoted string
Smoke [FAIL]: node -e "try { const m = require('./'); console.log('exports' in m ? 'exports present' : 'no exports') } catch (e) { console.error(e); process.exit(1) }
Output: sh: 1: Syntax error: Unterminated quoted string# Use Node.js 18 base image
FROM node:18-slim
# Create app directory
WORKDIR /usr/src/app
# Install dependencies (production only, to keep image lean)
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
# Copy source code
COPY . .
# Build if a build script is provided
RUN npm run build --if-present
# Default command: verify the module loads
CMD ["node", "-e", "require('./lib'); console.log('passport-jwt loaded')"]
node_modules coverage dist build .env .git
Concerns: Using npm ci --omit=dev may skip devDependencies needed for the build step; if a build script requires dev dependencies, npm run build could fail., The smoke test relies on requiring ./lib; if the library's actual entry point differs (e.g., lib/index.js vs. lib.js or a different path), the test may fail even if the package loads correctly.
Smoke [FAIL]: node -e 'require("./lib"); console.log("passport-jwt loaded")
Output: sh: 1: Syntax error: Unterminated quoted string
Smoke [FAIL]: node -e 'try { const m = require("./lib"); console.log("exports type: " + typeof m); } catch (e) { console.error(e); process.exit(1); }
Output: sh: 1: Syntax error: Unterminated quoted string# Use Node.js 18 base image FROM node:18-slim # Create app directory WORKDIR /usr/src/app # Install dependencies (production only to keep image lean) COPY package.json package-lock.json ./ RUN npm ci --omit=dev # Copy source code COPY . . # Optional build step (not required for this project) RUN npm run build --if-present # Smoke test script will run at container start CMD ["node", "test-run.js"]
const m = require('./lib');
console.log('passport-jwt loaded:', typeof m.Strategy, typeof m.ExtractJwt);
Concerns: COPY . . copies the entire context; consider adding a .dockerignore to avoid sending unnecessary files (e.g., local dev files, node_modules) to the build context., Optional build step uses --if-present, which is fine; ensure test-run.js handles cases where build artifacts are absent., If the project relies on devDependencies at runtime (unlikely since npm ci --omit=dev is used), verify runtime dependencies are sufficient.
Smoke [PASS]: ls -la /usr/src/app
Smoke [FAIL]: node -e "require('./'); console.log('module loaded')
Output: sh: 1: Syntax error: Unterminated quoted string
Smoke [FAIL]: node -e "console.log('package name:', require('./package.json').name)
Output: sh: 1: Syntax error: Unterminated quoted string# Multistage Dockerfile for passport-jwt
# Builder stage: install all dependencies (dev + prod)
FROM node:18 AS builder
WORKDIR /usr/src/app
# Install dependencies using the lockfile
COPY package.json package-lock.json ./
RUN npm ci
# Copy the rest of the repository
COPY . .
# Runtime stage: only production dependencies
FROM node:18-slim
WORKDIR /usr/src/app
# Copy only the production dependencies from the builder
COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/package.json ./package.json
COPY --from=builder /usr/src/app/package-lock.json ./package-lock.json
# Copy the rest of the application code
COPY --from=builder /usr/src/app .
# Verify the library loads at container start
CMD ["node", "-e", "require('./lib')"]
# Multistage Dockerfile for passport-jwt
# Builder stage: install all dependencies (dev + prod)
FROM node:18 AS builder
WORKDIR /usr/src/app
# Install dependencies using the lockfile
COPY package.json package-lock.json ./
RUN npm ci
# Copy the rest of the repository
COPY . .
# Runtime stage: only production dependencies
FROM node:18-slim
WORKDIR /usr/src/app
# Copy only the production dependencies from the builder
COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/package.json ./package.json
COPY --from=builder /usr/src/app/package-lock.json ./package-lock.json
# Copy the rest of the application code
COPY --from=builder /usr/src/app .
# Prune dev dependencies in the final image to keep it lean
RUN npm prune --production
# Verify the library loads at container start
CMD ["node", "-e", "require('./lib')"]
# Docker ignore for passport-jwt build node_modules coverage dist build test .git .gitignore .vscode .idea .env *.log
Smoke [FAIL]: node -e \"require('./lib')\
Output: sh: 1: Syntax error: "(" unexpected# Multistage Dockerfile for passport-jwt # Builder stage: install all dependencies (dev + prod) FROM node:18 AS builder WORKDIR /usr/src/app # Install dependencies using the lockfile COPY package.json package-lock.json ./ RUN npm ci # Copy the rest of the repository COPY . . # Runtime stage: only production dependencies FROM node:18-slim WORKDIR /usr/src/app # Copy only the production dependencies from the builder COPY --from=builder /usr/src/app/node_modules ./node_modules COPY --from=builder /usr/src/app/package.json ./package.json COPY --from=builder /usr/src/app/package-lock.json ./package-lock.json # Copy the rest of the application code COPY --from=builder /usr/src/app . # Prune dev dependencies in the final image to keep it lean RUN npm prune --production # Verify the library loads at container start CMD ["node", "lib/index.js"]
Smoke [FAIL]: test -f lib/index.js && echo 'index.js exists
Output: sh: 1: Syntax error: Unterminated quoted string
Smoke [FAIL]: node -e "require('./lib/index.js'); console.log('library-load-ok')
Output: sh: 1: Syntax error: Unterminated quoted string
Smoke [FAIL]: node -e "console.log('package-name=' + require('./package.json').name)
Output: sh: 1: Syntax error: Unterminated quoted string# Multistage Dockerfile for passport-jwt
# Builder stage: install all dependencies (dev + prod)
FROM node:18 AS builder
WORKDIR /usr/src/app
# Install dependencies using the lockfile
COPY package.json package-lock.json ./
RUN npm ci
# Copy the rest of the repository
COPY . .
# Runtime stage: only production dependencies
FROM node:18-slim
WORKDIR /usr/src/app
# Copy only the production dependencies from the builder
COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/package.json ./package.json
COPY --from=builder /usr/src/app/package-lock.json ./package-lock.json
# Copy the rest of the application code
COPY --from=builder /usr/src/app .
# Prune dev dependencies in the final image to keep it lean
RUN npm prune --production
# Verify the library loads at container start (exec form to avoid shell quoting issues in smoke tests)
CMD ["node", "-e", "require('./lib')"]