Skip to content

refactor(app): migrate to ES modules and drop unused mocha - #132

Merged
saidsef merged 1 commit into
mainfrom
refactor/migrate-to-esm
Jul 3, 2026
Merged

refactor(app): migrate to ES modules and drop unused mocha#132
saidsef merged 1 commit into
mainfrom
refactor/migrate-to-esm

Conversation

@saidsef

@saidsef saidsef commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

Modernises the app to ES modules and removes a dead devDependency. Behaviour is unchanged.

ES modules

  • Sets "type": "module" in app/package.json and converts the three source files from require/module.exports to import/export. Keeps the .js extension - no .mjs rename, which is the correct idiom for an all-ESM app.
  • Relative imports now carry their .js extension (./middleware.js, ./routes.js), as ESM requires.
  • Drops the 'use strict' pragmas, which are redundant under ES modules (always strict).

node: builtins

  • Core modules use the node: protocol (node:http, node:crypto) so they cannot be shadowed by a userland package.

Remove unused mocha

  • mocha was the only devDependency but there are no test files and the test script is a stub, so it was dead weight. Node's built-in node:test covers future needs.

Also bumps the minor version 1.5.2 -> 1.6.0.

Changes

  • app/package.json: add "type": "module", remove devDependencies (mocha), bump to 1.6.0
  • app/index.js, app/middleware.js, app/routes.js: CommonJS -> ESM, node: builtins

The explicit http.createServer(app) server handle is deliberately kept (useful for graceful shutdown, https/http2, or WebSockets).

Testing

Verified locally:

  • node --check passes for all three files as ES modules
  • No require / module.exports / 'use strict' remain; builtins use the node: prefix
  • npm install succeeds; mocha absent from node_modules
  • Server boots and logs Server is running on port 8080
  • GET /healthz returns {"status":"healthy"} (200)
  • GET / returns the expected JSON (Hello World!, random number, 40-char sha1) (200), confirming node:crypto resolves at runtime
  • Response headers still carry helmet's CSP and compression's Content-Encoding: gzip

No functional changes.

Convert the app from CommonJS to ES modules: set "type": "module" in
package.json and switch the three source files from require/module.exports
to import/export (keeping the .js extension - no .mjs rename). Relative
imports now carry their .js extension as ESM requires, and the redundant
'use strict' pragmas are dropped since ES modules are always strict.

Use the node: protocol for core builtins (node:http, node:crypto) so they
can never be shadowed by a userland package.

Remove the unused mocha devDependency: there are no test files and the
test script is a stub, so it was dead weight (Node's built-in node:test
covers future needs).

Behaviour is unchanged - the explicit http.createServer(app) server
handle is kept. Bump minor version 1.5.2 -> 1.6.0.
@saidsef saidsef added size/XS dependencies Pull requests that update a dependency file javascript Pull requests that update Javascript code labels Jul 3, 2026
@saidsef saidsef self-assigned this Jul 3, 2026
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@github-actions github-actions Bot added the preview preview label Jul 3, 2026
@saidsef-pr

saidsef-pr Bot commented Jul 3, 2026

Copy link
Copy Markdown

Application node-webserver-56e4f8a-132-pr-reviews has been created.

@saidsef-pr

saidsef-pr Bot commented Jul 3, 2026

Copy link
Copy Markdown

Application node-webserver-56e4f8a-132-pr-reviews is in state Running.
See more here: https://argocd.saidsef.co.uk/applications/node-webserver-56e4f8a-132-pr-reviews?operation=true

@saidsef-pr

saidsef-pr Bot commented Jul 3, 2026

Copy link
Copy Markdown

Application node-webserver-56e4f8a-132-pr-reviews is now running new version of deployments manifests.
See more here: https://argocd.saidsef.co.uk/applications/node-webserver-56e4f8a-132-pr-reviews?operation=true

@saidsef
saidsef merged commit b82e53b into main Jul 3, 2026
7 checks passed
@saidsef
saidsef deleted the refactor/migrate-to-esm branch July 3, 2026 13:03
@saidsef-pr

saidsef-pr Bot commented Jul 3, 2026

Copy link
Copy Markdown

Application node-webserver-56e4f8a-132-pr-reviews has been deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file javascript Pull requests that update Javascript code preview preview size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant