Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@threew/app

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@threew/app - npm Package Compare versions

Comparing version
1.0.1
to
1.0.2
+3
-3
package.json
{
"name": "@threew/app",
"version": "1.0.1",
"version": "1.0.2",
"main": "./dist/cjs/index.cjs",

@@ -25,4 +25,4 @@ "module": "./dist/esm/index.js",

},
"keywords": [],
"author": "",
"keywords": ["threew", "nodejs", "typescript", "backend", "framework", "web", "api", "rest", "server", "http", "router", "middleware", "express", "fast", "lightweight", "performance", "scalable", "body-parser", "logger", "rate-limiter", "static-server", "static-files", "modular"],
"author": "othreew",
"license": "ISC",

@@ -29,0 +29,0 @@ "description": "",

@@ -7,3 +7,2 @@ # @threew/app

- **Zero Runtime Dependencies**: Built entirely using Node.js native APIs.
- **Modern Architecture**: Modular design, ready to be split into sub-packages.

@@ -167,4 +166,102 @@ - **TypeScript First**: Full type safety and excellent developer experience.

## Static Files
Serve static files like HTML, CSS, JavaScript, images, and more:
### Basic Usage (ESM)
```typescript
import { createApp, staticFiles } from '@threew/app';
import path from 'path';
const app = createApp();
// Serve files from 'public' directory
app.use(staticFiles(path.join(process.cwd(), 'public')));
app.listen(3000);
```
### Basic Usage (CommonJS)
```javascript
const { createApp, staticFiles } = require('@threew/app');
const path = require('path');
const app = createApp();
// Serve static files from 'public' folder
app.use(staticFiles(path.join(__dirname, 'public')));
app.listen(3000);
```
### With Options
```typescript
app.use(staticFiles(path.join(process.cwd(), 'public'), {
index: 'index.html', // Default file for directories
maxAge: 86400000, // Cache duration in ms (1 day)
etag: true, // Enable ETag header
cacheControl: true, // Enable Cache-Control header
dotfiles: 'ignore', // How to handle dotfiles
lastModified: true, // Enable Last-Modified header
immutable: false, // Add immutable directive to cache
setHeaders: (res, filePath, stat) => {
// Custom headers per file
if (filePath.endsWith('.html')) {
res.setHeader('X-Custom', 'HTML file');
}
}
}));
```
### Multiple Directories
```typescript
// Serve from multiple folders (order matters)
app.use(staticFiles(path.join(process.cwd(), 'public')));
app.use(staticFiles(path.join(process.cwd(), 'uploads')));
app.use(staticFiles(path.join(process.cwd(), 'assets')));
```
### Manual File Serving
```typescript
import { sendFile } from '@threew/app';
// Serve specific file on route
app.get('/', sendFile(path.join(process.cwd(), 'public', 'index.html')));
app.get('/about', sendFile(path.join(process.cwd(), 'public', 'about.html')));
```
### Folder Structure Example
```
your-project/
├── public/
│ ├── index.html
│ ├── css/
│ │ └── style.css
│ ├── js/
│ │ └── app.js
│ └── images/
│ └── logo.png
├── src/
└── package.json
```
### Supported MIME Types
- HTML, CSS, JavaScript, JSON
- PNG, JPG, GIF, SVG, ICO, WebP
- WOFF, WOFF2, TTF, EOT
- PDF, ZIP, MP3, MP4
- And more...
</details>
## License
MIT