@nawal007/chooseserverport
v1.0.6
Published
choisir son port
Downloads
2
Readme
Hello World NPM
This is an example project to see the minimal amount effort needed to publish to NPM.
Installation
npm install @nawal007/chooseserverport
Usage
In Your Source Code
const myServer = require '@nawal007/chooseserverport';
//console.log(myServer(your function, your port)
//my function handleRequest:
const handleRequest = (req, response) => {
const path = url.parse(req.url, true).pathname;
if (path == "/") {
response.writeHead(200, {
"Content-Type": "text/html",
});
fs.readFile("./index.html", null, function (error, data) {
if (error) {
response.writeHead(404);
response.write("Fichier non trouvé");
} else {
response.write(data);
}
response.end();
});
}
if (path == "/date") {
const date = new Date().toString();
console.log(date);
}
if (path == "/hello") {
const QueryHello = url.parse(req.url, true).query.hello;
const QueryNom = url.parse(req.url, true).query.nom;
const QueryPrenom = url.parse(req.url, true).query.prenom;
console.log(QueryNom);
if (
QueryHello == undefined ||
QueryNom == undefined ||
QueryPrenom == undefined
) {
response.write(404);
} else {
response.write(
"<h1>" + QueryHello + " " + QueryPrenom + " " + QueryNom + "</h1>"
);
}
}
response.end();
};
//example myServer(handleRequest,4000)