Node.js Interview Questions and Tips

1. ECMAScript 6 (ES6) New Features:

Arrows

Arrows are a function shorthand using the => syntax. They are syntactically similar to the related feature in Java 8, C# and CoffeeScript. They support both statement block bodies as well as expression bodies which return the value of the expression. Unlike functions, arrows share the same lexical this as their surrounding code.

Classes

ES6 classes are a simple sugar over the prototype-based Object Oriented pattern. Having a single convenient declarative form makes class patterns easier to use, and encourages interoperability. Classes support prototype-based inheritance, super calls, instance and static methods and constructors.

Enhanced Object Literals

Object literals are extended to support setting the prototype at construction, shorthand for foo: foo assignments, defining methods, making super calls, and computing property names with expressions. Together, these also bring object literals and class declarations closer together, and let object-based design benefit from some of the same conveniences.

Template Strings

Template strings provide syntactic sugar for constructing strings. This is similar to string interpolation features in Perl, Python and more. Optionally, a tag can be added to allow the string construction to be customized, avoiding injection attacks or constructing higher level data structures from string contents.

Destructuring

Destructuring allows binding using pattern matching, with support for matching arrays and objects. Destructuring is fail-soft, similar to standard object lookup foo["bar"], producing undefined values when not found.

Let + Const

Block-scoped binding constructs. let is the new var. const is single-assignment. Static restrictions prevent use before assignment.

Iterators + For..Of

Iterator objects enable custom iteration like CLR IEnumerable or Java Iterable. Generalize for..in to custom iterator-based iteration with for..of. Don’t require realizing an array, enabling lazy design patterns like LINQ.

Iteration is based on these duck-typed interfaces (using TypeScript type syntax for exposition only):

Generators

Generators simplify iterator-authoring using function* and yield. A function declared as function* returns a Generator instance. Generators are subtypes of iterators which include additional next and throw. These enable values to flow back into the generator, so yield is an expression form which returns a value (or throws).

Note: Can also be used to enable ‘await’-like async programming, see also ES7 await proposal.

Unicode

Non-breaking additions to support full Unicode, including new Unicode literal form in strings and new RegExp u mode to handle code points, as well as new APIs to process strings at the 21bit code points level. These additions support building global apps in JavaScript.

Modules

Language-level support for modules for component definition. Codifies patterns from popular JavaScript module loaders (AMD, CommonJS). Runtime behaviour defined by a host-defined default loader. Implicitly async model – no code executes until requested modules are available and processed.

Some additional features include export default and export *:

Module Loaders

Module loaders support:

  • Dynamic loading
  • State isolation
  • Global namespace isolation
  • Compilation hooks
  • Nested virtualization

The default module loader can be configured, and new loaders can be constructed to evaluate and load code in isolated or constrained contexts.

Map + Set + WeakMap + WeakSet

Efficient data structures for common algorithms. WeakMaps provides leak-free object-key’d side tables.

Proxies

Proxies enable creation of objects with the full range of behaviors available to host objects. Can be used for interception, object virtualization, logging/profiling, etc.

Symbols

Symbols enable access control for object state. Symbols allow properties to be keyed by either string (as in ES5) or symbol. Symbols are a new primitive type. Optional description parameter used in debugging – but is not part of identity. Symbols are unique (like gensym), but not private since they are exposed via reflection features like Object.getOwnPropertySymbols.

Subclassable Built-ins

In ES6, built-ins like Array, Date and DOM Elements can be subclassed.

Object construction for a function named Ctor now uses two-phases (both virtually dispatched):

  • Call Ctor[@@create] to allocate the object, installing any special behavior
  • Invoke constructor on new instance to initialize

The known @@create symbol is available via Symbol.create. Built-ins now expose their @@create explicitly.

Math + Number + String + Array + Object APIs

Many new library additions, including core Math libraries, Array conversion helpers, String helpers, and Object.assign for copying.

Binary and Octal Literals

Two new numeric literal forms are added for binary (b) and octal (o).

Promises

Promises are a library for asynchronous programming. Promises are a first class representation of a value that may be made available in the future. Promises are used in many existing JavaScript libraries.

Reflect API

Full reflection API exposing the runtime-level meta-operations on objects. This is effectively the inverse of the Proxy API, and allows making calls corresponding to the same meta-operations as the proxy traps. Especially useful for implementing proxies.

Tail Calls

Calls in tail-position are guaranteed to not grow the stack unboundedly. Makes recursive algorithms safe in the face of unbounded inputs.

 

2. Tools are used in Node.js development

#1 Mocha.js

Mocha.js is a JavaScript test framework based on Node.js. It enables you to test both in console and in the browser. You can use this really fast testing suite to do the unit and integration testing plus it works for TDD (Test-Driven Development) and BDD (Behaviour Driven Development) perfectly. A big advantage of Mocha.js is that it’s modularity so you can easily use other libraries with is, such as Chai, Sinon or Should.js.

#2 Chai

Chai is a TDD and BDD assertion framework for Node.js which can be paired with any testing framework (like Mocha.js we just mentioned). We use Mocha.js to run asynchronous testes, but Chai helps us verify the test results. Chai can be run in a browser or with Node.js. As an assertion tool, we use Chai with its rich plugins (ex. chai-as-promised, chai-subset, chai-things). If we need to test Node.js HTTP servers, we usually use SuperTest https://github.com/visionmedia/supertest (it either makes real requests or simulates them while connected to Express.js)

#3 Sinon.JS

Sinon.js is a standalone testing framework for JavaScript. The great thing about is that it works with any testing framework. It supports stubs, spies and mocks. It also supports most browsers (cross-browser support) and runs on the server using Node.js.

#4 Express.js

Express.js is a must-use minimalist framework for Node.js web applications. A combination of Node.js and Express.js enables you to build software with JavaScript on the server side. Long story short, you could build a whole website with those two: using Node.js to build server-side part of the app and Express.js to publish the app on your website.

#5 WebStrom IDE

WebStorm IDE is an awesome IDE for Javascript. It’s lightweight and it has everything you need for building Node.js applications on the client side and server side. It’s a great tool if you’re doing only JavaScript/HTML/CSS development – WebStorm IDE is a tool made for JS <3.

You can do debugging, tracking (with built-in tool spy-js) and unit testing (with easy to integrate Karma or Mocha.js).

#6 Passport.js

Passport.js is an authentication middleware for Node.js. It gives you a choice of over 300 different ways of authenticating your app including username and password model, login via Facebook, Google, Twitter etc., and many other. It’s extremely easy to implement with any Express.js app.

#7 Socket.io

Socket.io is a framework that enables a bi-directional communication in real-time, based on events. It doesn’t matter which device or platform you’re using – it will work great on anything. The package includes real-time analytics with counters, logs and charts. It’s perfect for chat apps and it’s loved by both big companies such as Microsoft, Zendesk, Trello and small startups.

#8 Webpack

The main function of Webpack is to bundle JavaScript files for usage in a browser. You can create one or many bundles that are asynchronously loaded at a runtime – this reduces the initial loading time.

#9 BlueBird.js

BlueBird.js is a promise library, that helps you to control your asynchronous code. You can separate with it your code into different files without any problem. It’s a must-have if you care about a quality of your code. As an alternative, you can try the Q.

#10 PM2

PM2 is a process manager for Node.js applications. It ‘s simple to use and provides many useful built-in features (like load balancer or watch mode).

#11 Electrode.io

It’s an universal platform for React.js/Node.js applications. It’s brought by WalmartLabs which means that this set of tools had been tested on a huge amount of data. It’s not only a set of best practices, standardized structure and modern technologies – it also includes Electrode Explorer and Electrify. These tools let you explore all docs and components of your platform as well as visualize in a clear and appealing way the module tree of electrode.io + Webpack project bundles.

#12 Meteor.js

Meteor.js is a framework built for rapid prototyping of JavaScript apps and writing cross-platform code (Web, Android, iOS). It’s based on Node.js, integrated with MongoDB and you can use it with any JavaScript UI widget library. Even Y Combinator, the most influential startup accelerator, recommends this tool.

While Meteor.js is great for prototyping apps, it’s good to keep in mind that it might not be the best solution for maintaining the already finished ones.

#13 Vue.js

A great alternative for those who use Angular.js is Vue.js . If you don’t want to build a complex web app and have to configure routings, controllers and services then Vue.js could be the lightweight solution you’re looking for. This framework is focused on a ViewModel – you get features of larger frameworks in a lighter version for your single page applications.

#14 MEAN.JS

MEAN.js is a full-stack JavaScript solution for building web apps. The MEAN stack consists of MongoDB, Express.js, Angular.js and Node.js which means you can build web applications on the client and server side with one stack of tools.

#15 Babel

Babel is a JavaScript compiler. With Babel, you can compile an ECMAScript 6 to ECMAScript 5 easily. It allows you to use ES6 features in your projects and then compiles ES5 for you to use in production.

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.

 

Resource:

A Smarter Way to Learn JavaScript. The new tech-assisted approach that requires half the effort

Secrets of the JavaScript Ninja

Node.js Design Patterns

Web Development with MongoDB and NodeJS

Node.js the Right Way: Practical, Server-Side JavaScript That Scales

Web Development with Node and Express: Leveraging the JavaScript Stack

Learn NodeJS in 1 Day: Complete Node JS Guide with Examples

Learning Node: Moving to the Server-Side

Getting MEAN with Mongo, Express, Angular, and Node

Advertisements

About liyao13

Yao Li is a web and iOS developer, blogger and he has a passion for technology and business. In his blogs, he shares code snippets, tutorials, resources and notes to help people develop their skills. Donate $5 to him for a coffee with PayPal at About Me page and read more professional and interesting technical blog articles. Follow him @Yaoli0615 at Twitter to get latest tech updates.
This entry was posted in CS Research&Application, Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s