DEV Community

Amanda Cavallaro
Amanda Cavallaro

Posted on

Getting Started with Node.js

What is it all about?

  • A Back-end framework for JavaScript
  • It allows you to run JavaScript on the server
  • It's a javaScript runtime (it is not a programming language)
  • An extension to JavaScript
  • Native JSON Support
  • It's open source
  • Back-end technology
  • You can process multiple requests at the same time

Installing Node.js

Official Node.js Download link: https://nodejs.org/en/download/

  • LTS (Long Term Support) - Recommended for Most Users
  • Current - Latest features

Choose an IDE (Integrated Development Environment)

Bitesize definition of IDE from the BBC here.

Some examples of IDEs:

  • Brackets
  • Sublime Text
  • Visual Studio Code
  • Webstorm (not free)

NPM (Node Package Manager)

  • An open-source package manager for Node.js created in 2009
  • You can import and create your own packages
  • A package contains all the files needed for a module
  • package.json.The folder node_modules is where to find the modules

Creating a Simple Web Server

  • A web server
  • Import a package
  • HTTP stands for Hyper Text Transfer Protocol
  • List of Status codes: 200/ 300/ 400/ 500...
  • MIME Types: Content type
  • HTTP request methods (GET, HEAD, POST, PUT, DELETE ...)

Node.js API

  • API is the acronym for Application Programming Interface
  • Node.js comes with built-in packages and core modules
  • Index: https://nodejs.org/docs/latest/api/
  • To include a module, you can use require()
  • File System is one example: const fs = require('fs');

Terminology

  • CPU - Central Processing Unit - executes code, it's much faster than the RAM and the HD.
  • RAM - Random Access Memory. Short-term memory
  • HD - Hard drive. It reads the file. Long-term memory
  • Synchronous - Program is halted until resources are available
  • Asynchronous - The program continues executing and doesn't wait for resources to be available.
  • Arrow notation - clean way to write a callback function
  • Callback function - Prevents blocking, allows code to run
  • Middleware functions - have access to the request object (req) and the response object (res). It allows isolated functionalities to interact

Frameworks

  • Express.js
  • Nest.js
  • Koa.js
  • Meteor.js

Running a script

From the terminal type in node <name_of_the_file.js>

Top comments (0)