@@ -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
2728npm 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
64124Some of the features in ` response object ` are:
@@ -85,17 +145,16 @@ If you would like to contribute to Hasty Server, you're welcome to:
85145Note: 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
92153For 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- ```
100160All rights reserved to the author.
101- ```
0 commit comments