Skip to main content
FREE Mock interview & resume review with Sumit. Free right now, no payment needed.Book a slot

Node.js Fundamentals

Learn server-side JavaScript with Node.js.

jiocoder TeamUpdated Jun 6, 20261 min readNode.js
Node.js Fundamentals

What is Node.js?#

Node.js is a JavaScript runtime built on Chrome's V8 engine that allows you to run JavaScript on the server.

Creating a Server#

Code
const http = require('http');

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello World');
});

server.listen(3000, () => {
  console.log('Server running on port 3000');
});

File System#

Code
const fs = require('fs');

// Read file
fs.readFile('file.txt', 'utf8', (err, data) => {
  if (err) throw err;
  console.log(data);
});

// Write file
fs.writeFile('file.txt', 'Hello', (err) => {
  if (err) throw err;
});

Article discussion

(0)

Join the discussion — login to comment and help other developers.

Login to comment