Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 677 Bytes

3-first-application.md

File metadata and controls

38 lines (28 loc) · 677 Bytes

First Application

Import requires modules

const http = require('http');

Create a HTTP server

http
  .createServer((request, response) => {
    // Send the HTTP header
    // HTTP Status: 200 : OK
    // Content Type: text/plain
    response.writeHead(200, { 'Content-Type': 'text/plain' });

    // Send the response body as "Hello World"
    response.end('Hello World\n');
  })
  .listen(8081);

// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');

Create a HTTPS server

Read request and return response

node main.js
curl -XGET http://localhost:8081