Skip to content

Commit dcb2d66

Browse files
committed
Version update
1 parent 018286c commit dcb2d66

File tree

11 files changed

+148
-17
lines changed

11 files changed

+148
-17
lines changed

.gitignore

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
node_modules
2-
doc/v10
3-
doc/node_modules
1+
node_modules/
2+
dist/
3+
*.log
4+
.DS_Store
5+
/doc/v10
6+
/doc/node_modules
7+
/v10

README.md

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Bascially, It is my implementation of HTTP using raw TCP Socket in Javascript.
1111

1212
### table of contents
1313
- [Installation](#installation)
14+
- [Module Support](#module-support)
1415
- [Usage](#usage)
1516
- [Request Object](#request-object)
1617
- [Contributing](#contributing)
@@ -27,8 +28,46 @@ This is a work in progress and not ready for production. It is just a fun projec
2728
npm install hasty-server
2829
```
2930

31+
### Module Support
32+
33+
Hasty Server supports multiple module systems for maximum compatibility:
34+
35+
#### ✅ CommonJS (Default)
36+
37+
```javascript
38+
const Hasty = require('hasty-server');
39+
const server = new Hasty();
40+
```
41+
42+
#### ✅ ES Modules (ESM)
43+
44+
```javascript
45+
import Hasty from 'hasty-server';
46+
const server = new Hasty();
47+
```
48+
49+
#### ✅ TypeScript
50+
51+
```typescript
52+
import Hasty, { Request, Response } from 'hasty-server';
53+
54+
const server = new Hasty();
55+
56+
server.get('/', (req: Request, res: Response) => {
57+
res.json({ message: 'Hello from TypeScript!' });
58+
});
59+
```
60+
61+
#### ✅ Dual Package Support
62+
63+
The framework automatically detects your module system and provides the appropriate format:
64+
65+
- **CommonJS projects**: Uses `.js` files
66+
- **ESM projects**: Uses `.mjs` files
67+
- **TypeScript projects**: Uses `.d.ts` type definitions
68+
3069
### Usage
31-
70+
3271
**Common JS**
3372

3473
```Javascript
@@ -59,6 +98,27 @@ server.listen(8080, () => {
5998
});
6099
```
61100

101+
**TypeScript**
102+
103+
```typescript
104+
import Hasty, { Request, Response } from 'hasty-server';
105+
106+
const server = new Hasty();
107+
108+
server.get('/', (req: Request, res: Response) => {
109+
res.json({ message: 'Hello from TypeScript!' });
110+
});
111+
112+
server.post('/api/users', (req: Request, res: Response) => {
113+
const userData = req.body;
114+
res.status(201).json({ id: 1, ...userData });
115+
});
116+
117+
server.listen(8080, () => {
118+
console.log('TypeScript server running on port 8080');
119+
});
120+
```
121+
62122
### Request Object
63123

64124
Some of the features in `response object` are:
@@ -85,17 +145,16 @@ If you would like to contribute to Hasty Server, you're welcome to:
85145
Note: Do not use third-party code or dependencies. You can take help from language models, but avoid directly copying any of their code.
86146

87147
### CHANGELOG
88-
- v0.8.0
89-
- Added `download()` method to send file as an attachment.
90-
- Added `server.cors(true)` to enable `cors`.
148+
- v0.9.6
149+
- Added comprehensive module support (CommonJS, ESM, TypeScript)
150+
- Added dual package support with automatic module detection
151+
91152

92153
For more information, see .
93154
[CHANGELOG](CHANGELOG.md)
94155

95156
### LICENSE
96157

97-
This project is licensed under GOFL (Global Opensource softwares Free License) - see the [LICENSE](LICENSE.md) file for details.
158+
This project is licensed under LGPL-2.1 - see the [LICENSE](LICENSE.md) file for details.
98159

99-
```
100160
All rights reserved to the author.
101-
```

package.json

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
11
{
22
"name": "hasty-server",
33
"version": "0.9.6",
4-
"main": "./server/index.js",
4+
"main": "./dist/server/index.js",
5+
"type": "commonjs",
6+
"exports": {
7+
".": {
8+
"import": "./dist/server/index.mjs",
9+
"require": "./dist/server/index.js",
10+
"types": "./dist/types/server/index.d.ts"
11+
},
12+
"./response": {
13+
"import": "./dist/server/response.mjs",
14+
"require": "./dist/server/response.js",
15+
"types": "./dist/types/server/response.d.ts"
16+
},
17+
"./lib/*": {
18+
"import": "./dist/lib/*.mjs",
19+
"require": "./dist/lib/*.js",
20+
"types": "./dist/types/lib/*.d.ts"
21+
}
22+
},
23+
"types": "./dist/types/server/index.d.ts",
524
"directories": {
6-
"lib": "lib",
7-
"test": "test"
25+
"src": "src",
26+
"dist": "dist",
27+
"test": "test",
28+
"examples": "examples"
29+
},
30+
"scripts": {
31+
"build:esm": "node scripts/build-esm.js",
32+
"build:types": "tsc --declaration --emitDeclarationOnly --outDir dist/types",
33+
"build:commonjs": "node scripts/build-commonjs.js",
34+
"build": "npm run build:commonjs && npm run build:esm && npm run build:types",
35+
"clean": "rm -rf dist",
36+
"test": "node test/index.js"
837
},
9-
"scripts": {},
1038
"keywords": [
1139
"http",
1240
"server",
@@ -19,8 +47,8 @@
1947
"http"
2048
],
2149
"files": [
22-
"server/",
23-
"lib/",
50+
"dist/",
51+
"src/",
2452
"CONTRIBUTING.md",
2553
"LICENSE",
2654
"README.md",
@@ -35,5 +63,11 @@
3563
"homepage": "https://hasty-server.vercel.app",
3664
"license": "LGPL-2.1-only",
3765
"description": "A Blazing fast simple http server for node.js",
38-
"dependencies": {}
66+
"dependencies": {},
67+
"devDependencies": {
68+
"typescript": "^5.0.0"
69+
},
70+
"engines": {
71+
"node": ">=14.0.0"
72+
}
3973
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)