nemfile 1.0.2 → 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.
Files changed (3) hide show
  1. package/README.md +36 -0
  2. package/package.json +1 -1
  3. package/server.js +23 -0
package/README.md CHANGED
@@ -93,6 +93,38 @@ Open the **LAN** address on your phone — or scan the QR code shown on the page
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
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.
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nemfile",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
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",
package/server.js CHANGED
@@ -8,6 +8,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);
@@ -883,6 +884,23 @@ app.delete('/clear', (req, res) => {
883
884
  res.json({ ok: true, deleted: files.length });
884
885
  });
885
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
+
886
904
  app.post('/upload', upload.single('image'), (req, res) => {
887
905
  if (!req.file) return res.json({ ok: false, error: 'No file received' });
888
906
  const payload = { filename: req.file.filename, url: '/uploads/' + req.file.filename };
@@ -905,6 +923,11 @@ app.listen(PORT, '0.0.0.0', async () => {
905
923
  }
906
924
  }
907
925
 
926
+ if (NO_TUNNEL) {
927
+ console.log('\n Public tunnel disabled — LAN only.\n');
928
+ return;
929
+ }
930
+
908
931
  console.log('\n Starting public tunnel...');
909
932
 
910
933
  // Quick Tunnel (trycloudflare.com): anonymous, no Cloudflare account, no