Node.js Basics

The Essential Knowledge We Need

Hyerang Raina Kim
2 min readAug 6, 2020

How the Web Works

HTTP, HTTPS

Creating a Node Server

Core Modules

  • require: importing file
  • ./’ stands for local file, otherwise, it will look for the global module
  • createServer() takes a requestListner, a function that executes for every incoming request, as an argument
const http = require('http');http.createServer((req,res) => {
console.log(req);
});

After running this by using command,

node app.js

Nothing happens 😟!!

Why? We didn’t send a request to the server, and we don’t even know where the server is.

How do we reach the server? This creates the server method actually returns the server.

Now we store them in the variable:

const http = require('http');const server = http.createServer((req,res) => {
console.log(req);
});
server.listen(3000);

Node.js will keep this running to listen for incoming request. We then put the port number 300 to be local.

❓ See what happens on the web browser by entering localhost:3000.

✔️ Nothing since we haven’t set to return any html, but it’s still running, waiting for the request!!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response