background preloader

Node

Facebook Twitter

Debugging Node.js with Google Chrome – Node.js Collection – Medium. Debugging is the task to identify and remove errors from software applications, and is more than just printing out values in your code.

Debugging Node.js with Google Chrome – Node.js Collection – Medium

Creating a microservice in NodeJs. - JavaScript Developer and Blogger Published: Sat Apr 01 2017.

Creating a microservice in NodeJs

Build your first Node.js microservice - Max Stoibers Blog. A microservice is a single self-contained unit which, together with many others, makes up a large application.

Build your first Node.js microservice - Max Stoibers Blog

By splitting your app into small units every part of it is independently deployable and scalable, can be written by different teams and in different programming languages and can be tested individually. micro is a tiny (~100 LoC) module that makes writing a microservice in Node.js a joy. It’s easy to use and super fast. No matter if you’ve used Node.js before or not, after this post you’ll be able to write your own microservices! The Setup There are two tiny steps needed for the setup, first we need to install micro: Build a RESTful API Using Node and Express 4.

# Express Router and Routes We will use an instance of the Express Router to handle all of our routes.

Build a RESTful API Using Node and Express 4

Here is an overview of the routes we will require, what they will do, and the HTTP Verb used to access it. This will cover the basic routes needed for an API. This also keeps to a good format where we have kept the actions we need to execute (GET, POST, PUT, and DELETE) as HTTP verbs. # Route Middleware. Web App + REST API with Express, PostgreSQL and Nunjucks on Yarn. In this article I'll show you how to create a basic web application in Node from scratch.

Web App + REST API with Express, PostgreSQL and Nunjucks on Yarn

I'll be using yarn instead of npm. I issue HTTP requests using httpie instead of curl. Let's start with an empty directory: cd myapp $ yarn init Install express yarn add express Inside index.js, add first (root) route which renders a simple text: const express = require(‘express’) const app = express(); app.get('/', (req, res) => { res.send('Hello World') }) app.listen(3000, () => { console.log('listening on 3000') }) Auto-reloading Install nodemon to restart the server when there is a change yarn add nodemon --dev. Error Handling. Share: Error handling is a pain, and it's easy to get by for a long time in Node.js without dealing with many errors correctly.

Error Handling

But building robust Node.js apps requires dealing properly with errors, and it's not hard to learn how. If you're really impatient, skip down to the "Summary" section for a tl;dr. This document will answer several questions that programmers new to Node.js often ask: In functions that I write, when should I throw an error, and when should I emit it with a callback, event emitter, or something else?

This document is divided into several parts that build on one another: Background This document assumes: You're familiar with the idea of exceptions in JavaScript, Java, Python, C++, or any similar language, and that you know what it means to throw and catch them.You're familiar with programming in Node.js. Function myApiFunc(callback) { /* * This pattern does NOT work! Ryan Dahl: Original Node.js presentation. Understanding Socket.IO. Understanding Socket.IO It’s important to provide timely feedback to users in your web application.

Understanding Socket.IO

It all started with the introduction of XMLHttpRequest by Microsoft which became what we now know as AJAX. AJAX long-polling used to be the standard way to fetch server-sent data for an application, though it wasn’t the most ideal solution. Long-polling involves sending periodic HTTP requests for data, introducing latency and increasing server load. The IETF standardised WebSockets in 2011, providing a way for developers to send and receive data through a TCP socket. 10 Habits of a Happy Node Hacker (2016) At the tail end of 2015, JavaScript developers have a glut of tools at our disposal.

10 Habits of a Happy Node Hacker (2016)

The last time we looked into this, the modern JS landscape was just emerging. Today, it's easy to get lost in our huge ecosystem, so successful teams follow guidelines to make the most of their time and keep their projects healthy. Here are ten habits for happy Node.js hackers as we enter 2016. They're specifically for app developers, rather than module authors, since those groups have different goals and constraints: Best Practices for Node.js Development. Last updated 13 October 2015 For most of the nearly twenty years since its inception, JavaScript lacked many of the niceties that made other programming languages like Python and Ruby so attractive: command-line interfaces, a REPL, a package manager, and an organized open-source community.

Best Practices for Node.js Development

NodeSource - Enterprise Node.js Training, Support, Software & Consulting, Worldwide. Node's "event loop" is central to being able to handle high throughput scenarios.

NodeSource - Enterprise Node.js Training, Support, Software & Consulting, Worldwide

It is a magical place filled with unicorns and rainbows, and is the reason Node can essentially be "single threaded" while still allowing an arbitrary number of operations to be handled in the background. This post will shed light on how the event loop operates so you too can enjoy the magic. Event Driven Programming # The first thing needed in order to understand the event loop is an understanding of the event-driven programming paradigm.

This has been well understood since the 1960's. Defined simply: event-driven programming is application flow control that is determined by events or changes in state. For those familiar with client-side JavaScript development, think of all the .on*() methods, such as element.onclick(), that are used in conjunction with DOM Elements to convey user interaction. Top 10 Mistakes Node.js Developers Make.