Node.JS Nginx Manager - Part II

in NodeJS

This is the second post for the series of NodeJS Nginx Manager - nginx-upstream,
please consider reading the first part.

At the first part, I tried to describe how to install nginx-upstream and manage backend servers. Today, I will go for the rest of the methods of NginxUpstream class and how to use them.
Continue reading

Node.JS Nginx Manager - Part I

in NodeJS

Node.JS + Javascript and Nginx are the most popular stack that most busiest sites and APIs are using or considering to use. Especially Nginx is threatening other web servers and Node.JS / Javascript are huge hypes around web developers.

My type of guys - software development and open source addict - won’t miss such a trend, so I have started developing an application which is a SaaS for load balancing your applications. In its core, I am using Node.JS to manage Nginx configurations. Continue reading

Unnecessary Conditional Checks

in NodeJS

Penguin Logic
Misuse of conditional statements are not only hard to read, but also more complex for the processor.
Today, I want to underline some points about misused or over engineered conditional statements.

This image makes me smile everytime I see, and is a very good fit for our topic :)

So what do I mean about misused or over engineered conditional statement. I guess, some of these examples may bring up discussions, please comment with your rejections or approvals. I am always open for critics and learn from anyone.

Let me underline that the concepts I discuss is more applicaple if you are using ECMAScript5 and above.
Continue reading

Catching Callback

in Javascript

I would like to write about a common mistake of new javascript or nodejs developers make. Especially, the type of developers who have a high level language like C# or JAVA background. As you might know these languages are called multi paradigm programming languages, where you can find some of functional programming language concepts as well as object oriented concepts.

But in general, the execution and writing order of these languages are same. Meaning the lines at the start executes first. Let me show you a C# code block and describe what I mean.
Continue reading

Playing with Promises

in NodeJS

Either writing Javascript or NodeJS, we are always dealing with an asynchronous approach. We have to be very careful while implementing in this environment and also chanining callbacks will make your code not readable at all. - Even for yourself :) - General saying about this is Pyramid of Doom or Callback Hell

Let me give you an example - a developers day;

Pyramid of Doom or Callback Hell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
wakeup(function(alarm, callback) {
haveBreakfast(function(eggs) {
gotoOffice(function(car) {
writeCode(function(scrum, meeting, task) {
haveLunch(function(whereToEat) {
writeMoreCode(function(moretasks) {
gobackHome(function(car) {
haveDinner(function(isItReady) {
watchTV(function(phew) {
return calback('done with the day'));
})
})
})
})
})
})
})
})
})
Continue reading

Javascript Coding Style - Standard

in NPM

Coding is always fun when you are learning new stack or programming language and while learning, we are not always following the standard naming conventions or coding styles.

However coding style is very important if you are working within a project that contains multiple developers. Every software company can have their own standards, but applying this style for all projects is the hard part to manage.

So a common understanding of way of writing the code is one of the best practices that we have to follow. Some advantages of coding standards I can think of;

  • Easy to read someone elses code
  • Avoid simple mistakes
  • Easy maintanence
  • Less technical dept

Today I will talk about one of the most popular npm package standard for coding style of javascript. Why this is so popular, is that you do not need to make different configurations for your project. Only install it as a development dependency.
Continue reading

Javascript Type Definitions and NPM Packages

in NodeJS

Strong Type or Not

I enjoy writing javascript without depending on strong type definitions, but if you can somehow understand the parameter expectaction of a function, than it is realy helpful during development, even that function accepts any type of parameter(s).

Most javascript editors are capable of showing coding information, while you are writing. Even though, vi (vim) is my favorite, default vim is lacking of high level productivity tools. Currently, I am using Visual Studio Code (VSCode), which is working on all well know OS and has great addons like code highlighting, code snippets and intellisense.

On the other hand, having a good ide is not always enough, if the javascript code written as npm package or module does not contain a good type definition file. So while developing NodeJS and use well know packages, I can navigate to source code by clicking F12 on VSCode. Than curiosity take over the job and I started to investigate what is the best practive of doing this.
Continue reading

Express Web API

in API

Nowadays, web api is one of the most popular topic in our mobile world. And with NodeJS together with express framework, defining a web api takes minutes.

Basic API Definition With Express

Express framework initializer is very handy to create our example. To make use of it simply install it from npm. This will create express executable under /usr/bin/

1
npm install express-generator -g

Usage of express generator is also very easy. Execute the below command after installing express-generator and this will create the folder structure for you and some samples included to start your web application directly.

1
express firstapi

Continue reading

Define Service on Ubuntu

in Ubuntu

This blog is running over hexo blog framework which is powered by NodeJS.

The first thing, I did is to make hexo run at the boot of Ubuntu server or after hexo crashes somehow. There are multiple ways to do this, but here I will describe the latest practice over Ubuntu server.

I will describe for Ubuntu 16.04.2 LTS. To learn your ubuntu distribution version use command below;

1
2
3
4
5
6
lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial

Continue reading
Author's picture

Volkan N. Metin

Father of 2 beautiful kids
Computer Engineer
Software Development Adventurer


Software Development Manager


Istanbul, TR