nemfile 1.0.0 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -40,7 +40,7 @@ Getting a screenshot off an iPhone and onto a Windows or Linux machine usually m
40
40
  | Text clips | Paste text on one device, read it on another — a cross-platform clipboard |
41
41
  | One-click copy | Copy an image to the system clipboard, or copy its LAN URL |
42
42
  | Download buttons | Grab any uploaded file back down to whatever device you're on |
43
- | Public tunnel | Optional `localtunnel` URL so the page works outside your Wi-Fi |
43
+ | Public tunnel | Optional Cloudflare Tunnel URL so the page works outside your Wi-Fi |
44
44
  | Standalone binaries | Prebuilt executables for Linux, macOS and Windows — no Node needed |
45
45
 
46
46
  ## Install
@@ -86,16 +86,48 @@ nemfile prints three addresses:
86
86
  ```
87
87
  Local: http://localhost:3333
88
88
  LAN: http://192.168.1.10:3333 ← open this on your phone
89
- Public: https://xxxx.loca.lt ← works outside your Wi-Fi
89
+ Public: https://xxxx.trycloudflare.com ← works outside your Wi-Fi
90
90
  ```
91
91
 
92
92
  Open the **LAN** address on your phone — or scan the QR code shown on the page — and you get an upload box. Anything you drop there appears in the gallery on every connected device, and is written to `uploads/` on your computer.
93
93
 
94
94
  To share text instead of a file, paste into the text box and hit send; it shows up as a clip on every other device.
95
95
 
96
+ ### Flags
97
+
98
+ | Flag | Effect |
99
+ | --- | --- |
100
+ | `--no-tunnel`, `-L` | Don't start the public Cloudflare Tunnel — LAN only. |
101
+
102
+ ```bash
103
+ npx nemfile --no-tunnel
104
+ npx nemfile -L # same thing, shorter
105
+ ```
106
+
107
+ ### CLI / scripting (curl, no browser)
108
+
109
+ Every route works from a plain shell, so a headless machine can push and pull files without opening the page at all.
110
+
111
+ ```bash
112
+ # Upload a file — the multipart field must be named "image" (any file type works)
113
+ curl -F "image=@photo.png" http://192.168.1.10:3333/upload
114
+ # {"ok":true,"filename":"1699999999999-photo.png","url":"/uploads/1699999999999-photo.png"}
115
+
116
+ # List everything currently on the server, as JSON
117
+ curl http://192.168.1.10:3333/api/files
118
+ # {"ok":true,"files":[{"filename":"...","url":"/uploads/...","size":12345,"uploadedAt":"2026-...Z"}]}
119
+
120
+ # Download a file
121
+ curl -O http://192.168.1.10:3333/uploads/1699999999999-photo.png
122
+
123
+ # List + download every file in one line (needs jq)
124
+ curl -s http://192.168.1.10:3333/api/files | jq -r '.files[].url' | \
125
+ while read -r u; do curl -sO "http://192.168.1.10:3333$u"; done
126
+ ```
127
+
96
128
  ## How it works
97
129
 
98
- nemfile starts a small Express server on port `3333` bound to `0.0.0.0`, so any device on the same Wi-Fi can reach it. Uploads are handled by `multer` and written to `./uploads`. A server-sent-events stream keeps every open browser tab in sync, and `qrcode` renders the pairing QR codes. Optionally, `localtunnel` exposes the same page on a public HTTPS URL for when the two devices aren't on the same network.
130
+ nemfile starts a small Express server on port `3333` bound to `0.0.0.0`, so any device on the same Wi-Fi can reach it. Uploads are handled by `multer` and written to `./uploads`. A server-sent-events stream keeps every open browser tab in sync, and `qrcode` renders the pairing QR codes. Optionally, a Cloudflare Tunnel (no account needed) exposes the same page on a public HTTPS URL for when the two devices aren't on the same network.
99
131
 
100
132
  There is no database, no telemetry, and no external service in the default path — the LAN transfer is a direct HTTP request from your phone to your computer.
101
133
 
@@ -111,7 +143,7 @@ Yes — it covers the same job (send a file to a nearby device) but works betwee
111
143
 
112
144
  ### Do my files get uploaded to a cloud server?
113
145
 
114
- No. By default the transfer stays entirely on your local network. Files are saved to a folder on your own computer. The only exception is the optional public tunnel, which relays traffic through `loca.lt` so devices outside your Wi-Fi can reach the page — skip it if you don't need it.
146
+ No. By default the transfer stays entirely on your local network. Files are saved to a folder on your own computer. The only exception is the optional public tunnel, which relays traffic through Cloudflare so devices outside your Wi-Fi can reach the page — skip it if you don't need it.
115
147
 
116
148
  ### What's the maximum file size?
117
149
 
@@ -137,6 +169,10 @@ Port `3333`, bound to all interfaces so other devices on the network can connect
137
169
 
138
170
  In an `uploads/` directory created inside the folder you ran the command from. `cd` somewhere else first if you want them elsewhere.
139
171
 
172
+ ### Can I upload or list files from a script or a headless machine, without a browser?
173
+
174
+ Yes. `POST /upload` (multipart field `image`) and `GET /api/files` (JSON listing) both work from plain `curl` — see [CLI / scripting](#cli--scripting-curl-no-browser) above. Nothing about nemfile requires a browser; the web page is just the most convenient client for a phone.
175
+
140
176
  ### Is it safe to leave running?
141
177
 
142
178
  On a trusted home or office network, yes — but note that anyone who can reach the port can upload and browse files. Don't leave the public tunnel open on an untrusted network, and stop the server (`Ctrl+C`) when you're done.
package/bin/nemfile.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nemfile",
3
- "version": "1.0.0",
4
- "description": "Send files, screenshots and text between your phone, iPad and computer over local Wi-Fi — no cloud, no account, no app install. One command: npx nemfile.",
3
+ "version": "1.0.3",
4
+ "description": "Send files, screenshots and text between your phone, iPad and computer over local Wi-Fi \u2014 no cloud, no account, no app install. One command: npx nemfile.",
5
5
  "keywords": [
6
6
  "file-transfer",
7
7
  "share-files",
@@ -31,7 +31,7 @@
31
31
  "offline",
32
32
  "privacy",
33
33
  "tunnel",
34
- "localtunnel",
34
+ "cloudflare-tunnel",
35
35
  "express",
36
36
  "cli",
37
37
  "zero-config",
@@ -76,13 +76,14 @@
76
76
  "node20-win-x64"
77
77
  ],
78
78
  "assets": [
79
- "node_modules/qrcode/**/*"
79
+ "node_modules/qrcode/**/*",
80
+ "node_modules/cloudflared/bin/**/*"
80
81
  ],
81
82
  "outputPath": "dist"
82
83
  },
83
84
  "dependencies": {
85
+ "cloudflared": "^0.7.3",
84
86
  "express": "^4.18.2",
85
- "localtunnel": "^2.0.2",
86
87
  "multer": "^1.4.5-lts.1",
87
88
  "qrcode": "^1.5.4"
88
89
  }
package/server.js CHANGED
@@ -4,10 +4,11 @@ const path = require('path');
4
4
  const fs = require('fs');
5
5
  const os = require('os');
6
6
  const QRCode = require('qrcode');
7
- const localtunnel = require('localtunnel');
7
+ const { Tunnel } = require('cloudflared');
8
8
 
9
9
  const app = express();
10
10
  const PORT = 3333;
11
+ const NO_TUNNEL = process.argv.includes('--no-tunnel') || process.argv.includes('-L');
11
12
  const UPLOADS_DIR = path.join(process.cwd(), 'uploads');
12
13
 
13
14
  if (!fs.existsSync(UPLOADS_DIR)) fs.mkdirSync(UPLOADS_DIR);
@@ -81,7 +82,7 @@ app.get('/', async (req, res) => {
81
82
  <div class="thumb-meta">${f}</div>
82
83
  </a>
83
84
  <a class="thumb-dl" href="${url}" download="${f}" title="Download">↓</a>
84
- <button class="thumb-ln" data-url="${url}" onclick="copyLink(this)" title="Copy LAN link">URL</button>
85
+ <button class="thumb-ln" data-url="${url}" onclick="copyLink(this)" title="Copy link">URL</button>
85
86
  ${copyBtn}
86
87
  </div>`;
87
88
  }).join('');
@@ -536,7 +537,10 @@ app.get('/', async (req, res) => {
536
537
  border-left:2px solid var(--accent);
537
538
  }
538
539
  .qr.tunnel::before { border-color: var(--accent); }
539
- .qr img { display:block; width:96px; height:96px; }
540
+ .qr a { display: block; color: inherit; text-decoration: none; cursor: pointer; }
541
+ .qr img { display:block; width:96px; height:96px; transition: opacity .15s; }
542
+ .qr a:hover img { opacity: .8; }
543
+ .qr a:hover .qr-tag { color: var(--accent); }
540
544
  .qr-tag {
541
545
  font-size: 0.5rem;
542
546
  text-transform: uppercase;
@@ -649,19 +653,22 @@ app.get('/', async (req, res) => {
649
653
 
650
654
  <div class="qr-group">
651
655
  <div class="qr">
652
- <img src="${qrLan}" alt="LAN QR">
653
- <div class="qr-tag">// LAN</div>
654
- <div class="qr-url">${lanUrl}</div>
656
+ <a href="${lanUrl}" target="_blank" rel="noopener" title="Open ${lanUrl}">
657
+ <img src="${qrLan}" alt="LAN QR">
658
+ <div class="qr-tag">// LAN</div>
659
+ <div class="qr-url">${lanUrl}</div>
660
+ </a>
655
661
  </div>
656
662
  ${qrPublic ? `<div class="qr tunnel">
657
- <img src="${qrPublic}" alt="Public QR">
658
- <div class="qr-tag">// PUBLIC</div>
659
- <div class="qr-url">${publicUrl}</div>
663
+ <a href="${publicUrl}" target="_blank" rel="noopener" title="Open ${publicUrl}">
664
+ <img src="${qrPublic}" alt="Public QR">
665
+ <div class="qr-tag">// PUBLIC</div>
666
+ <div class="qr-url">${publicUrl}</div>
667
+ </a>
660
668
  </div>` : ''}
661
669
  </div>
662
670
 
663
671
  <script>
664
- const LAN_BASE = '${lanUrl}';
665
672
  const input = document.getElementById('fileInput');
666
673
  const statusEl = document.getElementById('status');
667
674
  const dropzone = document.getElementById('dropzone');
@@ -742,7 +749,7 @@ app.get('/', async (req, res) => {
742
749
  : '';
743
750
  const div = document.createElement('div');
744
751
  div.className = 'thumb' + (isNew ? ' thumb-new' : '');
745
- div.innerHTML = '<a href="' + url + '" target="_blank">' + preview + '<div class="thumb-meta">' + filename + '</div></a><a class="thumb-dl" href="' + url + '" download="' + filename + '" title="Download">↓</a><button class="thumb-ln" data-url="' + url + '" onclick="copyLink(this)" title="Copy LAN link">URL</button>' + copyBtn;
752
+ div.innerHTML = '<a href="' + url + '" target="_blank">' + preview + '<div class="thumb-meta">' + filename + '</div></a><a class="thumb-dl" href="' + url + '" download="' + filename + '" title="Download">↓</a><button class="thumb-ln" data-url="' + url + '" onclick="copyLink(this)" title="Copy link">URL</button>' + copyBtn;
746
753
  gallery.prepend(div);
747
754
  countEl.textContent = gallery.querySelectorAll('.thumb').length;
748
755
  if (isNew) setTimeout(() => div.classList.remove('thumb-new'), 4000);
@@ -803,11 +810,14 @@ app.get('/', async (req, res) => {
803
810
  flashBtn(btn, ok ? 'OK' : 'ERR', 'ok');
804
811
  }
805
812
 
806
- // Copy the file's LAN address, e.g. http://192.168.1.10:3333/uploads/x.png
813
+ // Copy the file's address using the origin the visitor is actually on
814
+ // (localhost, the LAN IP, or the public tunnel) — not a fixed LAN address,
815
+ // so the copied link still works for whoever pasted it.
807
816
  async function copyLink(btn) {
808
- const ok = await copyText(LAN_BASE + btn.dataset.url);
817
+ const fullUrl = location.origin + btn.dataset.url;
818
+ const ok = await copyText(fullUrl);
809
819
  flashBtn(btn, ok ? 'OK' : 'ERR', 'copied');
810
- setStatus(ok ? '// LINK COPIED — ' + LAN_BASE + btn.dataset.url : '// COPY FAILED', ok);
820
+ setStatus(ok ? '// LINK COPIED — ' + fullUrl : '// COPY FAILED', ok);
811
821
  setTimeout(() => setStatus('// AWAITING INPUT', false), 3000);
812
822
  }
813
823
 
@@ -874,6 +884,23 @@ app.delete('/clear', (req, res) => {
874
884
  res.json({ ok: true, deleted: files.length });
875
885
  });
876
886
 
887
+ // JSON file listing for scripts/CLI use — curl http://host:3333/api/files
888
+ app.get('/api/files', (req, res) => {
889
+ const files = fs.readdirSync(UPLOADS_DIR).sort().reverse();
890
+ res.json({
891
+ ok: true,
892
+ files: files.map(f => {
893
+ const stat = fs.statSync(path.join(UPLOADS_DIR, f));
894
+ return {
895
+ filename: f,
896
+ url: '/uploads/' + f,
897
+ size: stat.size,
898
+ uploadedAt: stat.mtime.toISOString(),
899
+ };
900
+ }),
901
+ });
902
+ });
903
+
877
904
  app.post('/upload', upload.single('image'), (req, res) => {
878
905
  if (!req.file) return res.json({ ok: false, error: 'No file received' });
879
906
  const payload = { filename: req.file.filename, url: '/uploads/' + req.file.filename };
@@ -896,23 +923,29 @@ app.listen(PORT, '0.0.0.0', async () => {
896
923
  }
897
924
  }
898
925
 
926
+ if (NO_TUNNEL) {
927
+ console.log('\n Public tunnel disabled — LAN only.\n');
928
+ return;
929
+ }
930
+
899
931
  console.log('\n Starting public tunnel...');
900
- try {
901
- const tunnel = await localtunnel({ port: PORT });
902
- publicUrl = tunnel.url;
903
- console.log(' Public: ' + publicUrl + ' ← use this outside LAN\n');
904
- console.log(' (First visit may ask for confirmation — click "Click to Continue")\n');
905
932
 
906
- tunnel.on('close', () => {
907
- publicUrl = null;
908
- console.log(' Tunnel closed.');
909
- });
910
- tunnel.on('error', err => {
911
- publicUrl = null;
912
- console.error(' Tunnel error:', err.message);
913
- });
914
- } catch (err) {
915
- console.error(' Could not create tunnel:', err.message);
916
- console.log(' → LAN only.\n');
917
- }
933
+ // Quick Tunnel (trycloudflare.com): anonymous, no Cloudflare account, no
934
+ // DNS setup — the binary itself is fetched automatically on `npm install`.
935
+ // Unlike the localtunnel relay this replaced, it doesn't silently die after
936
+ // a couple of requests, so a phone and a computer can both stay open on
937
+ // the gallery at once.
938
+ const tunnel = Tunnel.quick(`http://localhost:${PORT}`);
939
+
940
+ tunnel.once('url', url => {
941
+ publicUrl = url;
942
+ console.log(' Public: ' + publicUrl + ' ← use this outside LAN\n');
943
+ });
944
+ tunnel.on('error', err => {
945
+ console.error(' Tunnel error:', err.message);
946
+ });
947
+ tunnel.on('exit', () => {
948
+ publicUrl = null;
949
+ console.log(' Tunnel closed.');
950
+ });
918
951
  });