ServeJS is a JavaScript server-side framework for building server-rendered user interfaces
npm install serve-dot-jsServe-JS is a JavaScript server-side framework for building server-rendered user interfaces. Built to be adoptable on different levels, being component based while still used for templating.
sh
$ npm install serve-dot-js
`
๐ Examples
$3
This example demonstrates the use of ServeJS for serving files from a folder.
`js
const app = require("serve-dot-js");
app.listen(3000, () => console.log(Server started on port 3000));
`
Default folder it reads from is Src folder. In this folder contains the html, css and javascript files to be served. But this can be overwritten using a serveJS method. See example below.
`js
const app = require("serve-dot-js");
app.setView("Public"); // Changes the default folder for reading files from.
app.listen(3000, () => console.log(Server started on port 3000));
`
$3
Servejs allows you the freedom and flexibility to structure your apps the way you want.
See example below:
`js
const http = require("http");
const app = require("serve-dot-js");
http.createServer(app.route)
.listen(process.env.PORT || 4000, () => console.log('Server is running on PORT 3000'));
`
$3
This methods are used to assign function handlers to specific routes. Whenever the endpoint is hit and it matches the method type, the handler tied to that endpoint is called
#### ServeJS.prototype.get()
For GET requests.
#### ServeJS.prototype.post()
Adds endpoints with respective handlers for POST requests.
#### ServeJS.prototype.delete()
Adds endpoints for DELETE requests.
#### ServeJS.prototype.put()
For put requests.
#### ServeJS.prototype.options()
Adds endpoints for PUT requests.
โถ๏ธ Methods
$3
This method handles the whole routing process. It's passed as argument to http/https createServer methods.
$3
This sets the default folder for reading files from. Note: This is used if no custom route is set.
$3
This sets the default folder to serve files from. This is only used when custom routes are defined and a static file e.g css, js files, etc are requested.
$3
This function will tell ServeJS to log request details if given a value of __true__. Defualt value is false. Hence, ServeJS won't log requests by default.
$3
This is a mere wrapper around http and simply starts a http server for you, given a PORT.
$3
The render method is passed to the response object of routes' callbacks. res.render(fileName) will render file with fileName to the client.
$3
The primary functionality of this method is to send the file a file to the client. It accepts three parameters req, res, and filePath.
$3
This method is used for adding middlewares(functions) that will be called upon every request made. For a more targetted use of middlewares may be on a specific set of routes and not all routes please be sure to add it to the route definition.
$3
This is a serve middleware which if assigned, will make the value of req.body in JSON format.
$3
This serve middleware will keep req.body's value in it's raw form.
$3
This serve middleware returns req.body` as a string.
Made with โค๏ธ in Nigeria ๐ณ๐ฌ