27
loading...
This website collects cookies to deliver better user experience
httpwork
(this is the name of our framework). Now create a file named index.js
for it. Then create a file named test.js
.index.js
and test it in test.js
. const http = require('http'); // Add the http module
inServer
.function inServer(self){
// This general constructor function
};
serverSettings
and server
.function inServer(self){
var serverSetting;
var server;
};
serverSettings
variable, we enter what happens on the http server.var serverSettings = function(req, res){
res.write();
res.end();
}
write()
method, we specify that the self
parameter in the inServer
function must retrieve information from the write object. Our framework can retrieve user input using the self parameter.var serverSettings = function(req, res){
res.write(self['write']);
res.end();
}
function inServer(self){
var serverSettings = function(req, res){
res.write(self['write']);
res.end();
};
var server = http.createServer(serverSettings);
};
listen
method to the server
variable and take the port
object of the self
parameter in our inServer
function as a parameter:server.listen(self["port"]);
module.exports = {
inServer
}
const http = require('http');
function inServer(self){
var serverSettings = function(req, res){
res.write(self['write']);
res.end();
};
var server = http.createServer(serverSettings);
server.listen(self["port"]);
};
module.exports = {
inServer
}
test.js
):const app = require("./index.js");
var test = app.inServer({
write: "Hello, world",
port: 8000
});