1.0.6 • Published 2 years ago

@nawal007/chooseserverport v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Hello World NPM

This is an example project to see the minimal amount effort needed to publish to NPM.

Example CL Usage

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)
1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago