muriel1995
5/15/2019 - 6:35 AM

NODEJS http

NODEJS http

const http = require('http');
const port = 3000;


const requestHandler = (request, response) => {
  
  console.log(request.url);
  if (request.url === '/') {
    response.end('Bienvenue sur votre serveur !!')
  }else if (request.url === '/contact'){
    response.end('Nous ne sommes pas joignable pour le moment !')
  }else if (request.url.split('/').includes('display')){
    let name = request.url.split('/')
    response.end(`Vous tentez d'afficher le profil de ${name[name.lenght - 1]}`)
  }else {
    response.end('Erreur 404!')
  }
}
const server = http.createServer(requestHandler);


server.listen(port, (err) => {
  if (err) {
    throw new Error('Something bad happened...');
  }

  console.log(`server is listening on ${port}`);
});