DEV Community

Amanda Cavallaro
Amanda Cavallaro

Posted on

1

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>

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️