turbo-express-js 1.0.4 → 1.0.6

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 (184) hide show
  1. package/.history/.gitignore_20230512095955 +2 -0
  2. package/.history/.gitignore_20230626102051 +3 -0
  3. package/.history/.gitignore_20230626122931 +4 -0
  4. package/.history/.gitignore_20230626125037 +5 -0
  5. package/.history/.gitignore_20230626125046 +4 -0
  6. package/.history/README_20230609115231.md +201 -0
  7. package/.history/README_20230626092626.md +230 -0
  8. package/.history/README_20230626095658.md +231 -0
  9. package/.history/README_20230626105408.md +342 -0
  10. package/.history/README_20230626105410.md +342 -0
  11. package/.history/README_20230626122627.md +314 -0
  12. package/.history/README_20230626124240.md +365 -0
  13. package/.history/README_20230626124241.md +365 -0
  14. package/.history/README_20230626124244.md +365 -0
  15. package/.history/README_20230626124726.md +373 -0
  16. package/.history/README_20230626124736.md +371 -0
  17. package/.history/README_20230626124823.md +373 -0
  18. package/.history/README_20230626125116.md +373 -0
  19. package/.history/express.test_20230208141353.js +73 -0
  20. package/.history/express.test_20230626125006.js +73 -0
  21. package/.history/lib/ServerCallback_20230506184323.js +65 -0
  22. package/.history/lib/ServerCallback_20230626093331.js +67 -0
  23. package/.history/lib/ServerCallback_20230626093343.js +67 -0
  24. package/.history/lib/ServerCallback_20230626093429.js +65 -0
  25. package/.history/lib/TurboServer_20230623231925.js +334 -0
  26. package/.history/lib/TurboServer_20230626105248.js +336 -0
  27. package/.history/lib/enum/FileEndToContentType_20230116211639.js +35 -0
  28. package/.history/lib/enum/FileEndToContentType_20230705235813.js +38 -0
  29. package/.history/lib/middlewares/static_middleware_20230506180223.js +76 -0
  30. package/.history/lib/middlewares/static_middleware_20230705235748.js +74 -0
  31. package/.history/lib/services/AuthenticationService_20230622201613.js +206 -0
  32. package/.history/lib/services/AuthenticationService_20230626102428.js +206 -0
  33. package/.history/lib/services/AuthenticationService_20230626103611.js +208 -0
  34. package/.history/lib/services/AuthenticationService_20230626103612.js +208 -0
  35. package/.history/lib/services/AuthenticationService_20230626103822.js +208 -0
  36. package/.history/lib/types/RequestInterface_20230623230633.js +469 -0
  37. package/.history/lib/types/RequestInterface_20230626094947.js +469 -0
  38. package/.history/lib/types/ResponseInterface_20230623215215.js +104 -0
  39. package/.history/lib/types/ResponseInterface_20230626120918.js +109 -0
  40. package/.history/lib/types/ValidationSchema_20230623222435.js +227 -0
  41. package/.history/lib/types/ValidationSchema_20230626095116.js +225 -0
  42. package/.history/lib/types/default/index_20230626105118.js +0 -0
  43. package/.history/lib/types/default/index_20230626105212.js +8 -0
  44. package/.history/package_20230624023939.json +37 -0
  45. package/.history/package_20230626091751.json +38 -0
  46. package/.history/package_20230626093144.json +39 -0
  47. package/.history/package_20230626102134.json +40 -0
  48. package/.history/package_20230626115245.json +41 -0
  49. package/.history/package_20230626122632.json +41 -0
  50. package/.history/package_20230626123835.json +42 -0
  51. package/.history/package_20230626124052.json +40 -0
  52. package/.history/package_20230705235821.json +40 -0
  53. package/.history/samples/README_20230506174807.md +1 -0
  54. package/.history/samples/README_20230626122830.md +1 -0
  55. package/.history/samples/README_20230626122843.md +6 -0
  56. package/.history/samples/README_20230626123812.md +7 -0
  57. package/.history/samples/README_20230626123818.md +7 -0
  58. package/.history/samples/authentication.test_20230626095711.js +0 -0
  59. package/.history/samples/authentication.test_20230626095823.js +34 -0
  60. package/.history/samples/authentication.test_20230626095840.js +34 -0
  61. package/.history/samples/authentication.test_20230626101838.js +84 -0
  62. package/.history/samples/authentication.test_20230626101843.js +84 -0
  63. package/.history/samples/authentication.test_20230626101844.js +84 -0
  64. package/.history/samples/authentication.test_20230626102224.js +88 -0
  65. package/.history/samples/authentication.test_20230626102433.js +88 -0
  66. package/.history/samples/authentication.test_20230626102457.js +90 -0
  67. package/.history/samples/authentication.test_20230626102532.js +89 -0
  68. package/.history/samples/authentication.test_20230626102555.js +89 -0
  69. package/.history/samples/authentication.test_20230626102623.js +89 -0
  70. package/.history/samples/authentication.test_20230626102756.js +94 -0
  71. package/.history/samples/authentication.test_20230626103228.js +89 -0
  72. package/.history/samples/authentication.test_20230626103830.js +89 -0
  73. package/.history/samples/authentication.test_20230626104010.js +89 -0
  74. package/.history/samples/authentication.test_20230626104329.js +72 -0
  75. package/.history/samples/authentication.test_20230626105345.js +74 -0
  76. package/.history/samples/exesomething.test_20230626091442.js +19 -0
  77. package/.history/samples/exesomething.test_20230626091729.js +21 -0
  78. package/.history/samples/exesomething.test_20230626091815.js +19 -0
  79. package/.history/samples/exesomething.test_20230626091817.js +19 -0
  80. package/.history/samples/exesomething.test_20230626091855.js +19 -0
  81. package/.history/samples/exesomething.test_20230626091903.js +18 -0
  82. package/.history/samples/exesomething.test_20230626091959.js +27 -0
  83. package/.history/samples/index.test_20230626091149.js +0 -0
  84. package/.history/samples/index.test_20230626091311.js +12 -0
  85. package/.history/samples/index.test_20230626091344.js +12 -0
  86. package/.history/samples/index.test_20230626091420.js +17 -0
  87. package/.history/samples/index.test_20230626091421.js +17 -0
  88. package/.history/samples/index.test_20230626091443.js +19 -0
  89. package/.history/samples/middlewares.test_20230626105540.js +0 -0
  90. package/.history/samples/middlewares.test_20230626115222.js +29 -0
  91. package/.history/samples/middlewares.test_20230626115228.js +28 -0
  92. package/.history/samples/middlewares.test_20230626115248.js +28 -0
  93. package/.history/samples/middlewares.test_20230626115340.js +28 -0
  94. package/.history/samples/middlewares.test_20230626115427.js +28 -0
  95. package/.history/samples/middlewares.test_20230626115508.js +27 -0
  96. package/.history/samples/middlewares.test_20230626115702.js +33 -0
  97. package/.history/samples/middlewares.test_20230626115740.js +33 -0
  98. package/.history/samples/middlewares.test_20230626115942.js +34 -0
  99. package/.history/samples/middlewares.test_20230626115944.js +34 -0
  100. package/.history/samples/middlewares.test_20230626120053.js +47 -0
  101. package/.history/samples/middlewares.test_20230626120225.js +34 -0
  102. package/.history/samples/middlewares.test_20230626120651.js +49 -0
  103. package/.history/samples/middlewares.test_20230626120656.js +49 -0
  104. package/.history/samples/middlewares.test_20230626120733.js +49 -0
  105. package/.history/samples/middlewares.test_20230626120946.js +49 -0
  106. package/.history/samples/middlewares.test_20230626120951.js +49 -0
  107. package/.history/samples/middlewares.test_20230626121329.js +53 -0
  108. package/.history/samples/middlewares.test_20230626121710.js +54 -0
  109. package/.history/samples/middlewares.test_20230626121804.js +52 -0
  110. package/.history/samples/middlewares.test_20230626122848.js +49 -0
  111. package/.history/samples/request_response.test_20230626123122.js +0 -0
  112. package/.history/samples/request_response.test_20230626123444.js +51 -0
  113. package/.history/samples/request_response.test_20230626123451.js +51 -0
  114. package/.history/samples/request_response.test_20230626123755.js +51 -0
  115. package/.history/samples/request_response.test_20230626124254.js +51 -0
  116. package/.history/samples/request_response.test_20230626124255.js +51 -0
  117. package/.history/samples/request_response.test_20230626124304.js +51 -0
  118. package/.history/samples/request_response.test_20230626124317.js +51 -0
  119. package/.history/samples/request_response.test_20230626124339.js +53 -0
  120. package/.history/samples/request_response.test_20230626124402.js +55 -0
  121. package/.history/samples/request_response.test_20230626124548.js +56 -0
  122. package/.history/samples/request_response.test_20230626124601.js +56 -0
  123. package/.history/samples/request_response.test_20230626124656.js +51 -0
  124. package/.history/samples/validation.test_20230626092635.js +0 -0
  125. package/.history/samples/validation.test_20230626093127.js +48 -0
  126. package/.history/samples/validation.test_20230626093302.js +52 -0
  127. package/.history/samples/validation.test_20230626093311.js +49 -0
  128. package/.history/samples/validation.test_20230626093345.js +49 -0
  129. package/.history/samples/validation.test_20230626093401.js +51 -0
  130. package/.history/samples/validation.test_20230626093451.js +49 -0
  131. package/.history/samples/validation.test_20230626093505.js +51 -0
  132. package/.history/samples/validation.test_20230626093811.js +56 -0
  133. package/.history/samples/validation.test_20230626093905.js +66 -0
  134. package/.history/samples/validation.test_20230626093923.js +66 -0
  135. package/.history/samples/validation.test_20230626094131.js +71 -0
  136. package/.history/samples/validation.test_20230626094132.js +71 -0
  137. package/.history/samples/validation.test_20230626094658.js +65 -0
  138. package/.history/samples/validation.test_20230626094659.js +65 -0
  139. package/.history/samples/validation.test_20230626094700.js +65 -0
  140. package/.history/samples/validation.test_20230626122856.js +65 -0
  141. package/.history/todo_20230512093309.md +11 -0
  142. package/.history/todo_20230626124835.md +11 -0
  143. package/.history/todo_20230626124840.md +11 -0
  144. package/.history/todo_20230626124846.md +1 -0
  145. package/.history/todo_20230626124849.md +11 -0
  146. package/.history/todo_20230626124907.md +11 -0
  147. package/.history/version_management_20230506174323.md +13 -0
  148. package/.history/version_management_20230626124913.md +8 -0
  149. package/.history/version_management_20230626124950.md +10 -0
  150. package/README.md +223 -51
  151. package/lib/TurboServer.js +2 -0
  152. package/lib/enum/FileEndToContentType.js +28 -25
  153. package/lib/middlewares/static_middleware.js +3 -5
  154. package/lib/services/AuthenticationService.js +3 -1
  155. package/lib/types/RequestInterface.js +2 -2
  156. package/lib/types/ResponseInterface.js +5 -0
  157. package/lib/types/ValidationSchema.js +0 -2
  158. package/lib/types/default/index.js +8 -0
  159. package/package.json +8 -5
  160. package/samples/README.md +7 -1
  161. package/samples/authentication.test.js +74 -0
  162. package/samples/exesomething.test.js +27 -0
  163. package/samples/middlewares.test.js +49 -0
  164. package/samples/request_response.test.js +51 -0
  165. package/samples/validation.test.js +65 -0
  166. package/todo.md +3 -3
  167. package/version_management.md +4 -7
  168. package/bin/attachmentupload.test.js +0 -26
  169. package/bin/bin.test.js +0 -96
  170. package/bin/cors.test.js +0 -49
  171. package/bin/custombadrequesterror.test.js +0 -11
  172. package/bin/dynamicpath.test.js +0 -50
  173. package/bin/exemasterworker.test.js +0 -66
  174. package/bin/middleware.test.js +0 -44
  175. package/bin/preprod.test.js +0 -107
  176. package/locales/en/homepage.json +0 -3
  177. package/locales/gr/homepage.json +0 -3
  178. package/samples/5uo91B-4WVVFeSLPHupguHXw.png +0 -0
  179. package/samples/ELIhfER0oegQK0tz_CwOil_1.png +0 -0
  180. package/samples/Fo6AaX1yJ1tczanzboHrA_xY.png +0 -0
  181. package/test/index.js +0 -13
  182. package/test/package-lock.json +0 -217
  183. package/test/package.json +0 -15
  184. package/versions/index_v1_0_0.test.js +0 -115
@@ -0,0 +1,2 @@
1
+ public
2
+ node_modules
@@ -0,0 +1,3 @@
1
+ public
2
+ versions
3
+ node_modules
@@ -0,0 +1,4 @@
1
+ bin
2
+ public
3
+ versions
4
+ node_modules
@@ -0,0 +1,5 @@
1
+ bin
2
+ locales
3
+ public
4
+ versions
5
+ node_modules
@@ -0,0 +1,4 @@
1
+ bin
2
+ locales
3
+ public
4
+ node_modules
@@ -0,0 +1,201 @@
1
+ # TurboServer - A Fast and Powerful Node.js Web Framework
2
+
3
+ TurboServer is inspired by Express.js and offers a similar API to make it easy for developers familiar with Express to get started. In fact, TurboServer offers many of the same features and middleware that Express does, making it a great choice for developers who want a fast and efficient alternative to Express.
4
+
5
+ #
6
+
7
+ Additionally, TurboServer is built with an OOP architecture in mind, with Request and Response classes acting as interfaces. This makes it easy for developers to add new methods or override default functionality, leading to increased scalability and flexibility for your web applications.
8
+
9
+ #
10
+
11
+ ## Installation
12
+
13
+ To install TurboServer, simply run the following command:
14
+
15
+ ```
16
+ npm install turboserver
17
+ ```
18
+
19
+ ## Getting Started
20
+
21
+ Here's a simple example of how to create a basic server using TurboServer:
22
+
23
+ ``` javascript
24
+
25
+ const TurboServer = require('turboserver');
26
+
27
+ const app = new TurboServer(1);
28
+
29
+ app.get('/', (req, res) => {
30
+ res.send('Hello, World!');
31
+ });
32
+
33
+ app.listen(3000, () => {
34
+ console.log('Server started on port 3000');
35
+ });
36
+ ```
37
+
38
+ # Clustering
39
+
40
+ 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.
41
+
42
+ 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.
43
+
44
+ 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.
45
+
46
+ ## Middlewares
47
+
48
+ TurboServer includes a number of built-in middlewares that you can use to add functionality to your application. Here are some of the most commonly used middlewares:
49
+ Static
50
+
51
+ The Static middleware serves static files from a specified folder:
52
+
53
+ ``` javascript
54
+ app.use("/*", TurboServer.Static({ folder: '/public' }));
55
+ ```
56
+
57
+
58
+ # Upload
59
+
60
+ The Upload middleware handles file uploads:
61
+
62
+
63
+ ``` javascript
64
+ app.post('/upload', TurboServer.Upload({ folder: '/storage' }));
65
+ ```
66
+
67
+ ## Validation
68
+
69
+ The Validation middleware validates incoming requests against a specified schema (can validate by namespaces<params, query, body>):
70
+
71
+ ``` javascript
72
+ app.use("/user/new", TurboServer.Validation({
73
+ validations: [
74
+ new TurboServer.ValidationSchema("username", [
75
+ { name: TurboServer.ValidationMethodType.MINLENGTH, value: 3 },
76
+ { name: TurboServer.ValidationMethodType.MAXLENGTH, value: 14 },
77
+ { name: TurboServer.ValidationMethodType.ONEOF, value: ["Xristina"] }
78
+ ], true, "Default Value", "body")
79
+ ]
80
+ }));
81
+ ```
82
+
83
+ ## Authentication
84
+
85
+ The Authentication middleware handles user authentication:
86
+
87
+ *work in progress still
88
+
89
+ ``` javascript
90
+ const mongoose = require("mongoose");
91
+
92
+ const conn = mongoose.createConnection("mongodb://localhost:27017/testtest");
93
+
94
+ const userModel = conn.model("User", new mongoose.Schema({
95
+ username: String,
96
+ password: String
97
+ }))
98
+
99
+ const authService = new TurboServer.JWTBcryptMongoDBAuthService({ UserModel: userModel, useDbUser: true });
100
+
101
+ app.post("/login", async (req, res) => await authService.simpleLogin(req, res));
102
+ app.post("/login-double", async (req, res) => await authService.doubleLoginWorkflow(req, res));
103
+
104
+ app.use("/api/v1/*", TurboServer.Authentication({ authentication_service: authService }));
105
+ ```
106
+
107
+ ## BuildForm
108
+
109
+ The BuildForm middleware parses some sort of model and can generate list of fields for external app (reactJS, nextJS) or for template engine like EJS:
110
+
111
+ *work in progress still
112
+
113
+ ``` javascript
114
+ app.use("/api/v1/user/new", TurboServer.BuildForm());
115
+ ```
116
+
117
+ ## Cors
118
+
119
+ The Cors middleware adds CORS headers to responses:
120
+
121
+ *work in progress still
122
+
123
+ ``` javascript
124
+ app.use("/*", TurboServer.Cors());
125
+ ```
126
+
127
+
128
+ ## Custom Middleware
129
+
130
+ In addition to the built-in middlewares, TurboServer allows you to create your own custom middlewares for your application. Custom middleware functions can be used to add functionality to your application that is specific to your needs.
131
+
132
+ To create a custom middleware function, simply define a function that takes three parameters: the request object, the response object, and the next function. The next function is a callback that is used to pass control to the next middleware function in the chain.
133
+
134
+ Here's an example of a custom middleware function that logs the request method and URL to the console:
135
+
136
+ ``` javascript
137
+ function logger(req, res, next) {
138
+ console.log(`${req.method()} ${req.url()}`);
139
+ next();
140
+ }
141
+
142
+ app.use("/*", logger);
143
+ ```
144
+
145
+ In the above example, we define a logger function that logs the request method and URL to the console, and then calls the next function to pass control to the next middleware function in the chain. We then use the app.use method to add the logger function as a middleware function for all routes in our application.
146
+
147
+ You can define as many custom middleware functions as you need, and they will be executed in the order in which they are added to the middleware stack.
148
+
149
+ ## Custom Middleware after controller
150
+
151
+ In TurboServer, you can define middleware that will run after the controller method has completed. This can be useful for tasks such as logging, error handling, or any other post-processing that needs to be done after the response has been sent.
152
+
153
+ To define an end middleware in TurboServer, you can use the useEndMiddleware method. This method takes a path pattern and one or more middleware functions as arguments. The middleware functions will be executed in the order they are passed to the method.
154
+
155
+ Here is an example of how to define an end middleware in TurboServer:
156
+
157
+ ``` javascript
158
+ app.useEndMiddleware("/api/*", (req, res, next) => {
159
+ console.log("End middleware #1");
160
+ next();
161
+ }, (req, res, next) => {
162
+ console.log("End middleware #2");
163
+ next();
164
+ });
165
+ ```
166
+
167
+ #
168
+
169
+ ## Router
170
+
171
+ TurboServer offers a built-in Router to handle different HTTP methods and routes. The Router class is similar to the express.Router class, but it has some additional features. Here's a simple example of how to create a router and use it with TurboServer:
172
+
173
+ ``` javascript
174
+ const TurboServer = require('turboserver');
175
+
176
+ const app = new TurboServer(2);
177
+ const router = new TurboServer.Router();
178
+
179
+ router.get("/admin/:username", (req, res) => { res.send(req.params().get("username")) });
180
+
181
+ app.use('/api', router);
182
+
183
+ app.listen(3000, () => {
184
+ console.log('Server started on port 3000');
185
+ });
186
+
187
+ ```
188
+
189
+ ## About the Author
190
+
191
+ Our lead developer is a top-tier expert web and software engineer with mastery in over 20 programming languages, including Java, PHP, JavaScript, Golang, C, C++, and Python. With years of experience, they have built numerous open-source projects in these languages, including web, mobile, and desktop applications, as well as libraries and frameworks. Their expertise and passion for technology have been the driving force behind the creation of TurboServer, and they continue to work tirelessly to make it the fastest and most efficient web framework available.
192
+
193
+ #
194
+
195
+ ## Conclusion
196
+
197
+ TurboServer is a powerful and fast Node.js web framework that makes it easy to build high-performance web applications. With its built-in middlewares and simple API, it's a great choice for any project.
198
+
199
+ #
200
+
201
+ First deployment: 14/05/2023
@@ -0,0 +1,230 @@
1
+ # TurboServer - A Fast and Powerful Node.js Web Framework
2
+
3
+ TurboServer is inspired by Express.js and offers a similar API to make it easy for developers familiar with Express to get started. In fact, TurboServer offers many of the same features and middleware that Express does, making it a great choice for developers who want a fast and efficient alternative to Express.
4
+
5
+ #
6
+
7
+ Additionally, TurboServer is built with an OOP architecture in mind, with Request and Response classes acting as interfaces. This makes it easy for developers to add new methods or override default functionality, leading to increased scalability and flexibility for your web applications.
8
+
9
+ #
10
+
11
+ ## Installation
12
+
13
+ To install TurboServer, simply run the following command:
14
+
15
+ ```
16
+ npm install turboserver
17
+ ```
18
+
19
+ ## Getting Started
20
+
21
+ Here's a simple example of how to create a basic server using TurboServer:
22
+
23
+ ``` javascript
24
+
25
+ const TurboServer = require('turboserver');
26
+
27
+ const app = new TurboServer(1);
28
+
29
+ app.get('/', (req, res) => {
30
+ res.send('Hello, World!');
31
+ });
32
+
33
+ app.listen(3000, () => {
34
+ console.log('Server started on port 3000');
35
+ });
36
+ ```
37
+
38
+ # Clustering
39
+
40
+ 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.
41
+
42
+ 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.
43
+
44
+ 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.
45
+
46
+ ## Middlewares
47
+
48
+ TurboServer includes a number of built-in middlewares that you can use to add functionality to your application. Here are some of the most commonly used middlewares:
49
+ Static
50
+
51
+ The Static middleware serves static files from a specified folder:
52
+
53
+ ``` javascript
54
+ app.use("/*", TurboServer.Static({ folder: '/public' }));
55
+ ```
56
+
57
+
58
+ # Basic Execution
59
+ Executing code in master and worker cluster processes.
60
+ > turbo-express-js/samples/exesomething.test.js
61
+
62
+ ``` javascript
63
+ const TurboExpress = require("turbo-express-js");
64
+ const app = new TurboExpress(2);
65
+
66
+ TurboExpress.exeMaster(async () => console.log("This callback is executed in the master cluster process."););
67
+ TurboExpress.exeWorker(async () => console.log("This callback is executed on each worker cluster process."););
68
+
69
+ app.listen(5000);
70
+ ```
71
+
72
+ # Basic Execution
73
+ Executing code in master and worker cluster processes.
74
+ > turbo-express-js/samples/exesomething.test.js
75
+
76
+ ``` javascript
77
+ const TurboExpress = require("turbo-express-js");
78
+ const app = new TurboExpress(2);
79
+
80
+ TurboExpress.exeMaster(async () => console.log("This callback is executed in the master cluster process."););
81
+ TurboExpress.exeWorker(async () => console.log("This callback is executed on each worker cluster process."););
82
+
83
+ app.listen(5000);
84
+ ```
85
+
86
+
87
+ # Upload
88
+
89
+ The Upload middleware handles file uploads:
90
+
91
+
92
+ ``` javascript
93
+ app.post('/upload', TurboServer.Upload({ folder: '/storage' }));
94
+ ```
95
+
96
+ ## Validation
97
+
98
+ The Validation middleware validates incoming requests against a specified schema (can validate by namespaces<params, query, body>):
99
+
100
+ ``` javascript
101
+ app.use("/user/new", TurboServer.Validation({
102
+ validations: [
103
+ new TurboServer.ValidationSchema("username", [
104
+ { name: TurboServer.ValidationMethodType.MINLENGTH, value: 3 },
105
+ { name: TurboServer.ValidationMethodType.MAXLENGTH, value: 14 },
106
+ { name: TurboServer.ValidationMethodType.ONEOF, value: ["Xristina"] }
107
+ ], true, "Default Value", "body")
108
+ ]
109
+ }));
110
+ ```
111
+
112
+ ## Authentication
113
+
114
+ The Authentication middleware handles user authentication:
115
+
116
+ *work in progress still
117
+
118
+ ``` javascript
119
+ const mongoose = require("mongoose");
120
+
121
+ const conn = mongoose.createConnection("mongodb://localhost:27017/testtest");
122
+
123
+ const userModel = conn.model("User", new mongoose.Schema({
124
+ username: String,
125
+ password: String
126
+ }))
127
+
128
+ const authService = new TurboServer.JWTBcryptMongoDBAuthService({ UserModel: userModel, useDbUser: true });
129
+
130
+ app.post("/login", async (req, res) => await authService.simpleLogin(req, res));
131
+ app.post("/login-double", async (req, res) => await authService.doubleLoginWorkflow(req, res));
132
+
133
+ app.use("/api/v1/*", TurboServer.Authentication({ authentication_service: authService }));
134
+ ```
135
+
136
+ ## BuildForm
137
+
138
+ The BuildForm middleware parses some sort of model and can generate list of fields for external app (reactJS, nextJS) or for template engine like EJS:
139
+
140
+ *work in progress still
141
+
142
+ ``` javascript
143
+ app.use("/api/v1/user/new", TurboServer.BuildForm());
144
+ ```
145
+
146
+ ## Cors
147
+
148
+ The Cors middleware adds CORS headers to responses:
149
+
150
+ *work in progress still
151
+
152
+ ``` javascript
153
+ app.use("/*", TurboServer.Cors());
154
+ ```
155
+
156
+
157
+ ## Custom Middleware
158
+
159
+ In addition to the built-in middlewares, TurboServer allows you to create your own custom middlewares for your application. Custom middleware functions can be used to add functionality to your application that is specific to your needs.
160
+
161
+ To create a custom middleware function, simply define a function that takes three parameters: the request object, the response object, and the next function. The next function is a callback that is used to pass control to the next middleware function in the chain.
162
+
163
+ Here's an example of a custom middleware function that logs the request method and URL to the console:
164
+
165
+ ``` javascript
166
+ function logger(req, res, next) {
167
+ console.log(`${req.method()} ${req.url()}`);
168
+ next();
169
+ }
170
+
171
+ app.use("/*", logger);
172
+ ```
173
+
174
+ In the above example, we define a logger function that logs the request method and URL to the console, and then calls the next function to pass control to the next middleware function in the chain. We then use the app.use method to add the logger function as a middleware function for all routes in our application.
175
+
176
+ You can define as many custom middleware functions as you need, and they will be executed in the order in which they are added to the middleware stack.
177
+
178
+ ## Custom Middleware after controller
179
+
180
+ In TurboServer, you can define middleware that will run after the controller method has completed. This can be useful for tasks such as logging, error handling, or any other post-processing that needs to be done after the response has been sent.
181
+
182
+ To define an end middleware in TurboServer, you can use the useEndMiddleware method. This method takes a path pattern and one or more middleware functions as arguments. The middleware functions will be executed in the order they are passed to the method.
183
+
184
+ Here is an example of how to define an end middleware in TurboServer:
185
+
186
+ ``` javascript
187
+ app.useEndMiddleware("/api/*", (req, res, next) => {
188
+ console.log("End middleware #1");
189
+ next();
190
+ }, (req, res, next) => {
191
+ console.log("End middleware #2");
192
+ next();
193
+ });
194
+ ```
195
+
196
+ #
197
+
198
+ ## Router
199
+
200
+ TurboServer offers a built-in Router to handle different HTTP methods and routes. The Router class is similar to the express.Router class, but it has some additional features. Here's a simple example of how to create a router and use it with TurboServer:
201
+
202
+ ``` javascript
203
+ const TurboServer = require('turboserver');
204
+
205
+ const app = new TurboServer(2);
206
+ const router = new TurboServer.Router();
207
+
208
+ router.get("/admin/:username", (req, res) => { res.send(req.params().get("username")) });
209
+
210
+ app.use('/api', router);
211
+
212
+ app.listen(3000, () => {
213
+ console.log('Server started on port 3000');
214
+ });
215
+
216
+ ```
217
+
218
+ ## About the Author
219
+
220
+ Our lead developer is a top-tier expert web and software engineer with mastery in over 20 programming languages, including Java, PHP, JavaScript, Golang, C, C++, and Python. With years of experience, they have built numerous open-source projects in these languages, including web, mobile, and desktop applications, as well as libraries and frameworks. Their expertise and passion for technology have been the driving force behind the creation of TurboServer, and they continue to work tirelessly to make it the fastest and most efficient web framework available.
221
+
222
+ #
223
+
224
+ ## Conclusion
225
+
226
+ TurboServer is a powerful and fast Node.js web framework that makes it easy to build high-performance web applications. With its built-in middlewares and simple API, it's a great choice for any project.
227
+
228
+ #
229
+
230
+ First deployment: 14/05/2023
@@ -0,0 +1,231 @@
1
+ # TurboServer - A Fast and Powerful Node.js Web Framework
2
+
3
+ TurboServer is inspired by Express.js and offers a similar API to make it easy for developers familiar with Express to get started. In fact, TurboServer offers many of the same features and middleware that Express does, making it a great choice for developers who want a fast and efficient alternative to Express.
4
+
5
+ #
6
+
7
+ Additionally, TurboServer is built with an OOP architecture in mind, with Request and Response classes acting as interfaces. This makes it easy for developers to add new methods or override default functionality, leading to increased scalability and flexibility for your web applications.
8
+
9
+ #
10
+
11
+ ## Installation
12
+
13
+ To install TurboServer, simply run the following command:
14
+
15
+ ```
16
+ npm install turboserver
17
+ ```
18
+
19
+ ## Getting Started
20
+
21
+ Here's a simple example of how to create a basic server using TurboServer:
22
+
23
+ ``` javascript
24
+
25
+ const TurboServer = require('turboserver');
26
+
27
+ const app = new TurboServer(1);
28
+
29
+ app.get('/', (req, res) => {
30
+ res.send('Hello, World!');
31
+ });
32
+
33
+ app.listen(3000, () => {
34
+ console.log('Server started on port 3000');
35
+ });
36
+ ```
37
+
38
+ # Clustering
39
+
40
+ 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.
41
+
42
+ 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.
43
+
44
+ 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.
45
+
46
+ ## Middlewares
47
+
48
+ TurboServer includes a number of built-in middlewares that you can use to add functionality to your application. Here are some of the most commonly used middlewares:
49
+ Static
50
+
51
+ The Static middleware serves static files from a specified folder:
52
+
53
+ ``` javascript
54
+ app.use("/*", TurboServer.Static({ folder: '/public' }));
55
+ ```
56
+
57
+
58
+ # Basic Execution
59
+ Executing code in master and worker cluster processes.
60
+ > turbo-express-js/samples/exesomething.test.js
61
+
62
+ ``` javascript
63
+ const TurboExpress = require("turbo-express-js");
64
+ const app = new TurboExpress(2);
65
+
66
+ TurboExpress.exeMaster(async () => console.log("This callback is executed in the master cluster process."););
67
+ TurboExpress.exeWorker(async () => console.log("This callback is executed on each worker cluster process."););
68
+
69
+ app.listen(5000);
70
+ ```
71
+
72
+ # Request Validation and Handling
73
+ Validate and handle HTTP requests with Turbo Express. (Out of the box feature)
74
+ > turbo-express-js/samples/validation.test.js
75
+
76
+ ``` javascript
77
+ const TurboExpress = require("turbo-express-js");
78
+ const app = new TurboExpress(2);
79
+
80
+ TurboExpress.exeMaster(async () => console.log("This callback is executed in the master cluster process."););
81
+ TurboExpress.exeWorker(async () => console.log("This callback is executed on each worker cluster process."););
82
+
83
+ app.listen(5000);
84
+ ```
85
+ This section demonstrates how to validate and handle HTTP requests using Turbo Express. The example includes a create_user function that serves as the request handler. If the request passes the validation, the handler function processes the request and sends a response. However, if the request does not pass the validation, Turbo Express automatically returns a 400 response with the validation errors. Additionally, Turbo Express provides a ValidationError class/interface that you can override for handling custom error messages and supporting multiple languages. For more advanced usage and customization options, refer to the official documentation of Turbo Express at the project's website.
86
+
87
+
88
+ # Upload
89
+
90
+ The Upload middleware handles file uploads:
91
+
92
+
93
+ ``` javascript
94
+ app.post('/upload', TurboServer.Upload({ folder: '/storage' }));
95
+ ```
96
+
97
+ ## Validation
98
+
99
+ The Validation middleware validates incoming requests against a specified schema (can validate by namespaces<params, query, body>):
100
+
101
+ ``` javascript
102
+ app.use("/user/new", TurboServer.Validation({
103
+ validations: [
104
+ new TurboServer.ValidationSchema("username", [
105
+ { name: TurboServer.ValidationMethodType.MINLENGTH, value: 3 },
106
+ { name: TurboServer.ValidationMethodType.MAXLENGTH, value: 14 },
107
+ { name: TurboServer.ValidationMethodType.ONEOF, value: ["Xristina"] }
108
+ ], true, "Default Value", "body")
109
+ ]
110
+ }));
111
+ ```
112
+
113
+ ## Authentication
114
+
115
+ The Authentication middleware handles user authentication:
116
+
117
+ *work in progress still
118
+
119
+ ``` javascript
120
+ const mongoose = require("mongoose");
121
+
122
+ const conn = mongoose.createConnection("mongodb://localhost:27017/testtest");
123
+
124
+ const userModel = conn.model("User", new mongoose.Schema({
125
+ username: String,
126
+ password: String
127
+ }))
128
+
129
+ const authService = new TurboServer.JWTBcryptMongoDBAuthService({ UserModel: userModel, useDbUser: true });
130
+
131
+ app.post("/login", async (req, res) => await authService.simpleLogin(req, res));
132
+ app.post("/login-double", async (req, res) => await authService.doubleLoginWorkflow(req, res));
133
+
134
+ app.use("/api/v1/*", TurboServer.Authentication({ authentication_service: authService }));
135
+ ```
136
+
137
+ ## BuildForm
138
+
139
+ The BuildForm middleware parses some sort of model and can generate list of fields for external app (reactJS, nextJS) or for template engine like EJS:
140
+
141
+ *work in progress still
142
+
143
+ ``` javascript
144
+ app.use("/api/v1/user/new", TurboServer.BuildForm());
145
+ ```
146
+
147
+ ## Cors
148
+
149
+ The Cors middleware adds CORS headers to responses:
150
+
151
+ *work in progress still
152
+
153
+ ``` javascript
154
+ app.use("/*", TurboServer.Cors());
155
+ ```
156
+
157
+
158
+ ## Custom Middleware
159
+
160
+ In addition to the built-in middlewares, TurboServer allows you to create your own custom middlewares for your application. Custom middleware functions can be used to add functionality to your application that is specific to your needs.
161
+
162
+ To create a custom middleware function, simply define a function that takes three parameters: the request object, the response object, and the next function. The next function is a callback that is used to pass control to the next middleware function in the chain.
163
+
164
+ Here's an example of a custom middleware function that logs the request method and URL to the console:
165
+
166
+ ``` javascript
167
+ function logger(req, res, next) {
168
+ console.log(`${req.method()} ${req.url()}`);
169
+ next();
170
+ }
171
+
172
+ app.use("/*", logger);
173
+ ```
174
+
175
+ In the above example, we define a logger function that logs the request method and URL to the console, and then calls the next function to pass control to the next middleware function in the chain. We then use the app.use method to add the logger function as a middleware function for all routes in our application.
176
+
177
+ You can define as many custom middleware functions as you need, and they will be executed in the order in which they are added to the middleware stack.
178
+
179
+ ## Custom Middleware after controller
180
+
181
+ In TurboServer, you can define middleware that will run after the controller method has completed. This can be useful for tasks such as logging, error handling, or any other post-processing that needs to be done after the response has been sent.
182
+
183
+ To define an end middleware in TurboServer, you can use the useEndMiddleware method. This method takes a path pattern and one or more middleware functions as arguments. The middleware functions will be executed in the order they are passed to the method.
184
+
185
+ Here is an example of how to define an end middleware in TurboServer:
186
+
187
+ ``` javascript
188
+ app.useEndMiddleware("/api/*", (req, res, next) => {
189
+ console.log("End middleware #1");
190
+ next();
191
+ }, (req, res, next) => {
192
+ console.log("End middleware #2");
193
+ next();
194
+ });
195
+ ```
196
+
197
+ #
198
+
199
+ ## Router
200
+
201
+ TurboServer offers a built-in Router to handle different HTTP methods and routes. The Router class is similar to the express.Router class, but it has some additional features. Here's a simple example of how to create a router and use it with TurboServer:
202
+
203
+ ``` javascript
204
+ const TurboServer = require('turboserver');
205
+
206
+ const app = new TurboServer(2);
207
+ const router = new TurboServer.Router();
208
+
209
+ router.get("/admin/:username", (req, res) => { res.send(req.params().get("username")) });
210
+
211
+ app.use('/api', router);
212
+
213
+ app.listen(3000, () => {
214
+ console.log('Server started on port 3000');
215
+ });
216
+
217
+ ```
218
+
219
+ ## About the Author
220
+
221
+ Our lead developer is a top-tier expert web and software engineer with mastery in over 20 programming languages, including Java, PHP, JavaScript, Golang, C, C++, and Python. With years of experience, they have built numerous open-source projects in these languages, including web, mobile, and desktop applications, as well as libraries and frameworks. Their expertise and passion for technology have been the driving force behind the creation of TurboServer, and they continue to work tirelessly to make it the fastest and most efficient web framework available.
222
+
223
+ #
224
+
225
+ ## Conclusion
226
+
227
+ TurboServer is a powerful and fast Node.js web framework that makes it easy to build high-performance web applications. With its built-in middlewares and simple API, it's a great choice for any project.
228
+
229
+ #
230
+
231
+ First deployment: 14/05/2023