sindibadthesailor

Basic Node.js server

Apr 15th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Charger module HTTP
  2. var http = require("http");
  3.  
  4. //Créer serveur HTTP et écoute sur le port 8000 pour les requêtes
  5. http.createServer(function (request, response) {
  6.  
  7.    // insérer header HTTP dqns lq réponse avec status  HTTP et le Content type
  8.    response.writeHead(200, {'Content-Type': 'text/plain'});
  9.    
  10.    // envoyer  "Hello World" dans le body de la réponse
  11.    response.end('Hello World\n');
  12. }).listen(8000);
  13.  
  14. // sortie de l'URL d'accés au serveur sur la console (écran de commande)
  15. console.log('Server running at http://127.0.0.1:8000/')
Advertisement
Add Comment
Please, Sign In to add comment