turbo-express-js 1.0.8 → 1.0.10

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.
package/README.md CHANGED
@@ -1,22 +1,29 @@
1
- # TurboServer - A Fast and Powerful Node.js Web Server Framework
1
+ # Turbo Express JS 🚀
2
2
 
3
- TurboServer is inspired by Express.js
4
- and offers a similar API to make it easy for developers familiar with Express to get started.
5
- In fact, TurboServer offers many of the same features and middleware that Express does,
6
- making it a great choice for developers who want a fast and efficient alternative to Express.
3
+ **Minimalistic, Fast and Powerful Node.js Framework**
4
+ **(Express + JSON Parser + CORS + Cookie Parser + Upload + Validation + Authentication)**
5
+
6
+ > 🔄 Express compatible structure, but OOP driven and built-in all middlewares.
7
7
 
8
8
  > Made with ❤️ by Mike Karypidis
9
9
 
10
- #
11
10
 
12
- Additionally, TurboServer is built with an OOP architecture in mind,
13
- with Request and Response classes acting as interfaces.
14
- This makes it easy for developers to add new methods or override default functionality,
15
- leading to increased scalability and flexibility for your web applications.
16
11
 
17
- #
12
+ ## ✨ Features
13
+
14
+ - Zero external dependency setup (JSON, CORS, Cookie, Upload built-in)
15
+ - Extendable `Request` and `Response` (OOP interfaces)
16
+ - Authentication system out of the box
17
+ - Validation middleware out of the box
18
+ - Clustering support (spawn multiple workers)
19
+ - Post-controller middleware execution
20
+ - Locales (i18n) ready
21
+
22
+ ---
18
23
 
19
- ## Installation
24
+
25
+
26
+ ## 🔧 Installation
20
27
 
21
28
  To install TurboServer, simply run the following command:
22
29
 
@@ -24,7 +31,9 @@ To install TurboServer, simply run the following command:
24
31
  npm install turbo-express-js
25
32
  ```
26
33
 
27
- ## Getting Started
34
+
35
+
36
+ ## 👌 Getting Started
28
37
 
29
38
  Here's a simple example of how to create a basic server using TurboServer:
30
39
 
@@ -32,7 +41,7 @@ Here's a simple example of how to create a basic server using TurboServer:
32
41
 
33
42
  const TurboServer = require('turboserver');
34
43
 
35
- const app = new TurboServer(1);
44
+ const app = new TurboServer();
36
45
 
37
46
  app.get('/', (req, res) => {
38
47
  res.send('Hello, World!');
@@ -43,15 +52,74 @@ Here's a simple example of how to create a basic server using TurboServer:
43
52
  });
44
53
  ```
45
54
 
55
+
56
+
57
+ # 🔬 Comparison: Express.js vs Turbo Express JS
58
+
59
+ | Feature | Express.js | Turbo Express JS |
60
+ |:---|:---|:---|
61
+ | Built-in JSON Body Parsing | ❌ | ✅ |
62
+ | Built-in CORS Middleware | ❌ | ✅ |
63
+ | Built-in File Upload Support | ❌ | ✅ |
64
+ | Authentication System | ❌ | ✅ |
65
+ | OOP Request/Response Extendable | ❌ | ✅ |
66
+ | Cluster Support | ❌ (manual) | ✅ (out of the box) |
67
+ | Validation Middleware | ❌ | ✅ |
68
+ | Post-Controller Middlewares | ❌ | ✅ |
69
+ | Locales (i18n) | ❌ | ✅ |
70
+ | Performance Focus | ✅ | ✅ |
71
+
72
+
73
+
74
+ ## 📦 TypeScript Support
75
+
76
+ Turbo Express JS works perfectly with TypeScript.
77
+ It includes a ready-to-use `index.d.ts` file with support for:
78
+
79
+ - Request/Response interfaces
80
+ - Class-based routing
81
+ - Autocomplete & type checking
82
+ - Full OOP method overriding
83
+
84
+
85
+
86
+
87
+ ### ✅ Basic Example in TypeScript
88
+
89
+
90
+
91
+ ```ts
92
+ // main.ts
93
+ import TurboServer = require("turbo-express-js");
94
+
95
+ const app = new TurboServer();
96
+
97
+ app.get("/", (req, res) => {
98
+ res.send("Hello from TypeScript + Turbo Express JS!");
99
+ });
100
+
101
+ app.listen(3000, () => {
102
+ console.log("TurboExpress running on http://localhost:3000");
103
+ });
104
+ ```
105
+
106
+
107
+
46
108
  # Clustering
47
109
 
48
110
  TurboServer is built to support clustering out of the box. By passing a number to the TurboServer constructor, you can specify how many worker processes to spawn for your application.
49
111
 
112
+ ``` javascript
113
+ const app = new TurboServer(2);
114
+ ```
115
+
50
116
  In the example above, const app = new TurboServer(2) tells TurboServer to start two worker processes for the server. This allows the server to handle multiple requests simultaneously, improving the performance and scalability of your application.
51
117
 
52
118
  To take full advantage of the clustering feature, it's important to make sure your application is stateless and doesn't rely on local variables or in-memory storage. With proper configuration, clustering can help your application handle a large number of requests with ease.
53
119
 
54
- # Middlewares
120
+
121
+
122
+ # 🔍 Middlewares
55
123
  TurboServer includes a number of built-in middlewares that you can use to add functionality to your application. Here are some of out of the box middlewares:
56
124
 
57
125
  1. Cors middleware
package/changelog.md CHANGED
@@ -11,4 +11,10 @@
11
11
 
12
12
  # 1.0.7 stable
13
13
  1. [18/8/2023] update TurboExpress.Cors() fix bug that throw an error if it not recieve props
14
- 2. [18/8/2023] update documentations
14
+ 2. [18/8/2023] update documentations
15
+
16
+ # 1.0.8 docs changes
17
+
18
+ # 1.0.9 - 1.0.10
19
+ 1. [25/4/2025] update clusters, 0 argument mean no clusters.
20
+ 2. [25/4/2025] first typescript support
package/index.d.ts ADDED
@@ -0,0 +1,124 @@
1
+ // index.d.ts
2
+ /// <reference types="node" />
3
+
4
+ import { IncomingMessage, ServerResponse } from "http";
5
+
6
+ export = TurboServer;
7
+
8
+ declare class TurboServer {
9
+ constructor(clusterslength?: number);
10
+
11
+ static Router: typeof Router;
12
+ static AuthenticationService: any;
13
+ static ValidationTypes: any;
14
+ static ExpressServices: any;
15
+ static TurboExpressDefault: any;
16
+ static Log: any;
17
+ static Util: any;
18
+
19
+ static Static(options?: { folder?: string; cache?: boolean }): Function;
20
+ static Cors(options?: { origins?: string[]; credentials?: boolean; methods?: string[]; headers?: string[] }): Function;
21
+ static Upload(options?: { folder?: string; memory?: boolean }): Function;
22
+ static Validation(options?: any): Function;
23
+ static RunMethod(options?: { exe: any[] }): Function;
24
+ static Authentication(options?: { authentication_service: any }): Function;
25
+ static BuildForm(options?: any): Function;
26
+ static exeMaster(callback: () => Promise<void>): Promise<void>;
27
+ static exeWorker(callback: () => Promise<void>): Promise<void>;
28
+
29
+ Request: typeof RequestInterface;
30
+ Response: typeof ResponseInterface;
31
+
32
+ use(path: string, ...callbacks: Function[]): void;
33
+ useEndMiddleware(path: string, ...callbacks: Function[]): void;
34
+
35
+ get(path: string, ...callbacks: Function[]): void;
36
+ post(path: string, ...callbacks: Function[]): void;
37
+ put(path: string, ...callbacks: Function[]): void;
38
+ delete(path: string, ...callbacks: Function[]): void;
39
+ head(path: string, ...callbacks: Function[]): void;
40
+ patch(path: string, ...callbacks: Function[]): void;
41
+ options(path: string, ...callbacks: Function[]): void;
42
+ link(path: string, ...callbacks: Function[]): void;
43
+ unlink(path: string, ...callbacks: Function[]): void;
44
+ view(path: string, ...callbacks: Function[]): void;
45
+ lock(path: string, ...callbacks: Function[]): void;
46
+ unlock(path: string, ...callbacks: Function[]): void;
47
+ copy(path: string, ...callbacks: Function[]): void;
48
+ purge(path: string, ...callbacks: Function[]): void;
49
+ propfind(path: string, ...callbacks: Function[]): void;
50
+ all(path: string, ...callbacks: Function[]): void;
51
+
52
+ getServer(): import("http").Server;
53
+ setLocales(localeDirectory: string): void;
54
+ listen(port: number, callback?: () => void): void;
55
+ logRoutes(): void;
56
+ }
57
+
58
+ declare class Router {
59
+ constructor(path?: string);
60
+
61
+ get(path: string, ...callbacks: Function[]): void;
62
+ post(path: string, ...callbacks: Function[]): void;
63
+ put(path: string, ...callbacks: Function[]): void;
64
+ delete(path: string, ...callbacks: Function[]): void;
65
+ head(path: string, ...callbacks: Function[]): void;
66
+ patch(path: string, ...callbacks: Function[]): void;
67
+ options(path: string, ...callbacks: Function[]): void;
68
+ link(path: string, ...callbacks: Function[]): void;
69
+ unlink(path: string, ...callbacks: Function[]): void;
70
+ view(path: string, ...callbacks: Function[]): void;
71
+ lock(path: string, ...callbacks: Function[]): void;
72
+ unlock(path: string, ...callbacks: Function[]): void;
73
+ copy(path: string, ...callbacks: Function[]): void;
74
+ purge(path: string, ...callbacks: Function[]): void;
75
+ propfind(path: string, ...callbacks: Function[]): void;
76
+
77
+ use(path: string, ...callbacks: Function[]): void;
78
+ }
79
+
80
+ declare class RequestInterface {
81
+ IncomingMessage: IncomingMessage;
82
+ models: Map<string, any>;
83
+ content_type: string;
84
+ current_locale: string;
85
+ ValidationError: any;
86
+ _body: Buffer;
87
+ _files: any[];
88
+ _validations: any[];
89
+ _validation_errors: any[];
90
+ _body_hash: any;
91
+
92
+ params(): Map<string, any>;
93
+ paramsObj(): Record<string, any>;
94
+ queries(): URLSearchParams;
95
+ queriesObj(): Record<string, any>;
96
+ headers(): IncomingMessage["headers"];
97
+ method(): string;
98
+ url(): string;
99
+ httpVersion(): string;
100
+ remoteAddress(): string;
101
+ remotePort(): number;
102
+ localAddress(): string;
103
+ localPort(): number;
104
+
105
+ body(): Promise<any>;
106
+ body_hash(): any;
107
+ files(): any[];
108
+
109
+ setState(key: string, value: any): void;
110
+ useState(key: string): any;
111
+ getStateObj(): Record<string, any>;
112
+
113
+ getText(key: string): string | null;
114
+ }
115
+
116
+ declare class ResponseInterface {
117
+ OutgoingMessage: ServerResponse;
118
+ models: Map<string, any>;
119
+
120
+ status(code: number): this;
121
+ send(body: string, contentType?: string): void;
122
+ json(data: object): void;
123
+ header(key: string, value: string): void;
124
+ }
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ // updated !!
1
2
  const TurboServer = require("./lib/TurboServer");
2
3
 
3
4
  module.exports = TurboServer;
package/index.test.js CHANGED
@@ -2,12 +2,10 @@ const TurboExpress = require("./lib/TurboServer");
2
2
  const RequestInterface = require("./lib/types/RequestInterface");
3
3
  const ResponseInterface = require("./lib/types/ResponseInterface");
4
4
 
5
- const app = new TurboExpress(1);
5
+ const app = new TurboExpress();
6
6
 
7
- // 6976355584
7
+ // console.log("testing development...")
8
8
 
9
- // app.get("/", (req, res) => {req.}, (req, res) => {req.});
9
+ app.get("asd", ()=>{ })
10
10
 
11
- // app.use("/asd", new TurboExpress.Router)
12
-
13
- app.listen(3001, () => console.log("Server is running on port 3000"));
11
+ app.listen(3001, () => console.log("Service is running"));
@@ -221,6 +221,7 @@ module.exports = class TurboServer
221
221
  /** @type {Map<String, import("mongoose").Model} */ models = new Map();
222
222
  /** @type {Map<String, import("mongoose").Model} */ sqlModels = new Map(); // TODO later
223
223
  /** @type {import("./services/LocaleService")} */ localeService = new ExpressServices.LocaleService();
224
+ /** @type {Boolean} */ useClusters = true;
224
225
 
225
226
  /**
226
227
  * @param {Number} CLUSTERSLENGTH
@@ -230,6 +231,15 @@ module.exports = class TurboServer
230
231
  */
231
232
  constructor (CLUSTERSLENGTH)
232
233
  {
234
+ if(!CLUSTERSLENGTH)
235
+ {
236
+ global["TurboExpress"] = new Object();
237
+ global["TurboExpressCaching"] = new Object();
238
+ this.#server = http.createServer(ServerCallback.bind(this));
239
+ this.Request = RequestInterface;
240
+ this.Response = ResponseInterface;
241
+ this.useClusters = false;
242
+ }
233
243
  if (cluster.isMaster) {
234
244
  for (let i = 0; i < CLUSTERSLENGTH; i++) { cluster.fork() }
235
245
  } else {
@@ -249,39 +259,39 @@ module.exports = class TurboServer
249
259
  */
250
260
 
251
261
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
252
- get(path, ...callbacks){if(!cluster.isMaster) {this.__get_routes.push(new Route(path, RequestMethods.GET, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
262
+ get(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__get_routes.push(new Route(path, RequestMethods.GET, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
253
263
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
254
- post(path, ...callbacks){if(!cluster.isMaster) {this.__post_routes.push(new Route(path, RequestMethods.POST, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
264
+ post(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__post_routes.push(new Route(path, RequestMethods.POST, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
255
265
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
256
- put(path, ...callbacks){if(!cluster.isMaster) {this.__put_routes.push(new Route(path, RequestMethods.PUT, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
266
+ put(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__put_routes.push(new Route(path, RequestMethods.PUT, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
257
267
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
258
- delete(path, ...callbacks){if(!cluster.isMaster) {this.__delete_routes.push(new Route(path, RequestMethods.DELETE, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
268
+ delete(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__delete_routes.push(new Route(path, RequestMethods.DELETE, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
259
269
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
260
- head(path, ...callbacks){if(!cluster.isMaster) {this.__head_routes.push(new Route(path, RequestMethods.HEAD, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
270
+ head(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__head_routes.push(new Route(path, RequestMethods.HEAD, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
261
271
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
262
- patch(path, ...callbacks){if(!cluster.isMaster) {this.__patch_routes.push(new Route(path, RequestMethods.PATCH, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
272
+ patch(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__patch_routes.push(new Route(path, RequestMethods.PATCH, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
263
273
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
264
- options(path, ...callbacks){if(!cluster.isMaster) {this.__options_routes.push(new Route(path, RequestMethods.OPTIONS, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
274
+ options(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__options_routes.push(new Route(path, RequestMethods.OPTIONS, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
265
275
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
266
- link(path, ...callbacks){if(!cluster.isMaster) {this.__link_routes.push(new Route(path, RequestMethods.LINK, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
276
+ link(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__link_routes.push(new Route(path, RequestMethods.LINK, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
267
277
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
268
- unlink(path, ...callbacks){if(!cluster.isMaster) {this.__unlink_routes.push(new Route(path, RequestMethods.UNLINK, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
278
+ unlink(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__unlink_routes.push(new Route(path, RequestMethods.UNLINK, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
269
279
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
270
- view(path, ...callbacks){if(!cluster.isMaster) {this.__view_routes.push(new Route(path, RequestMethods.VIEW, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
280
+ view(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__view_routes.push(new Route(path, RequestMethods.VIEW, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
271
281
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
272
- lock(path, ...callbacks){if(!cluster.isMaster) {this.__lock_routes.push(new Route(path, RequestMethods.LOCK, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
282
+ lock(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__lock_routes.push(new Route(path, RequestMethods.LOCK, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
273
283
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
274
- unlock(path, ...callbacks){if(!cluster.isMaster) {this.__unlock_routes.push(new Route(path, RequestMethods.UNLOCK, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
284
+ unlock(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__unlock_routes.push(new Route(path, RequestMethods.UNLOCK, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
275
285
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
276
- copy(path, ...callbacks){if(!cluster.isMaster) {this.__copy_routes.push(new Route(path, RequestMethods.COPY, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
286
+ copy(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__copy_routes.push(new Route(path, RequestMethods.COPY, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
277
287
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
278
- purge(path, ...callbacks){if(!cluster.isMaster) {this.__purge_routes.push(new Route(path, RequestMethods.PURGE, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
288
+ purge(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__purge_routes.push(new Route(path, RequestMethods.PURGE, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
279
289
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
280
- propfind(path, ...callbacks){if(!cluster.isMaster) {this.__propfind_routes.push(new Route(path, RequestMethods.PROPFIND, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
290
+ propfind(path, ...callbacks){if(!cluster.isMaster || this.useClusters === false) {this.__propfind_routes.push(new Route(path, RequestMethods.PROPFIND, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
281
291
 
282
292
  /** @param {String} path; @param {TurboExpressCallback[]} callbacks */
283
293
  all(path, ...callbacks){
284
- if(!cluster.isMaster) {
294
+ if(!cluster.isMaster || this.useClusters === false) {
285
295
  const rMethods = new RequestMethods();
286
296
  rMethods.forEach((m) => this[`__${m}_routes`].push(new Route(path, m, callbacks, this.__middlewares_begin, this.__middlewares_end)));
287
297
  }
@@ -353,8 +363,8 @@ module.exports = class TurboServer
353
363
  listen (port, cb)
354
364
  {
355
365
  /** will listen not on master cluster ... */
356
- if(!cluster.isMaster) {
357
- this.#server.listen(port, cb ? cb : () => console.log("server is running"))
366
+ if(!cluster.isMaster || this.useClusters === false) {
367
+ this.#server.listen(port, cb || (() => console.log("server is running " + port)))
358
368
  }
359
369
  }
360
370
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "turbo-express-js",
3
- "version": "1.0.8",
4
- "description": "turbo express performance security easy to use web server framework ",
3
+ "version": "1.0.10",
4
+ "description": "Turbo Express JS - Performance, Security, Easy-to-use Web Server Framework",
5
5
  "main": "index.js",
6
6
  "directories": {
7
7
  "lib": "lib"
@@ -20,6 +20,7 @@
20
20
  "cors": "nodemon samples/cors.test.js",
21
21
  "validation_override": "nodemon samples/validation_override.test.js"
22
22
  },
23
+ "types": "index.d.ts",
23
24
  "repository": {
24
25
  "type": "git",
25
26
  "url": "git+https://github.com/breathfunwithmindte/turbo-express.git"
@@ -27,16 +28,20 @@
27
28
  "keywords": [
28
29
  "web",
29
30
  "server",
30
- "framwork",
31
+ "framework",
31
32
  "lightweight",
32
33
  "minimalistic",
33
34
  "superfast",
34
- "fast"
35
+ "fast",
36
+ "nodejs",
37
+ "express",
38
+ "turbo",
39
+ "turbo-express"
35
40
  ],
36
41
  "author": "Mike Karypidis",
37
42
  "license": "MIT",
38
43
  "bugs": {
39
44
  "url": "https://github.com/breathfunwithmindte/turbo-express/issues"
40
45
  },
41
- "homepage": "https://github.com/breathfunwithmindte/turbo-express#readme"
46
+ "homepage": "https://github.com/mikekarypidis/turbo-express-js"
42
47
  }