O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Learning Node.js for .NET Developers

Book Description

Solve practical real-world problems using JavaScript and Node.js

About This Book

  • Learn the concepts of Node.js to gain a high-level understanding of the Node.js execution model
  • Build an interactive web application with MongoDB and Redis and create your own JavaScript modules that work both on the client side and server side
  • Familiarize yourself with the new features of Node.js and JavaScript with this exclusive step-by-step guide

Who This Book Is For

This book is for developers who want to learn JavaScript and Node.js. Previous experience with programming is desired, but no JavaScript or Node.js knowledge is required. The book focuses mostly on web development, such as networking, serving dynamic pages, and real-time client-server communication.

What You Will Learn

  • Understand which problems Node.js best solves
  • Write idiomatic JavaScript and Node.js code
  • Build web applications and command-line tools
  • Minimise complexity and efficiently solve difficult problems
  • Test and deploy Node.js applications
  • Work with persistent data
  • Implement real-time client-server applications
  • Integrate .NET and Node.js code

In Detail

Node.js is an open source, cross-platform runtime environment that allows you to use JavaScript to develop server-side web applications.

This short guide will help you develop applications using JavaScript and Node.js, leverage your existing programming skills from .NET or Java, and make the most of these other platforms through understanding the Node.js programming model. You will learn how to build web applications and APIs in Node, discover packages in the Node.js ecosystem, test and deploy your Node.js code, and more. Finally, you will discover how to integrate Node.js and .NET code.

Style and approach

This is a step-by-step and practical guide to Node.js for .Net developers. It covers the fundamentals relating to typical applications. The focus is on providing the practical skills required to develop applications, with a summary of the key concepts covered.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Learning Node.js for .NET Developers
    1. Table of Contents
    2. Learning Node.js for .NET Developers
    3. Credits
    4. About the Author
    5. About the Reviewer
    6. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why subscribe?
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Why Node.js?
      1. What is Node.js?
        1. Understanding the Node.js execution model
          1. Non-blocking
          2. Event-driven
          3. Single-threaded
        2. Introducing the Node.js ecosystem
      2. Why JavaScript?
        1. A clear canvas
        2. Functional nature
        3. A bright future
      3. When to use Node.js
        1. Writing web applications
        2. Identifying other use cases
        3. Why now?
      4. Summary
    9. 2. Getting Started with Node.js
      1. Installing and running Node.js
      2. Choosing an editor
      3. Using an application framework
        1. Getting started with Express
        2. Exploring our Express application
        3. Understanding Express routes and views
        4. Using nodemon for automatic restarts
        5. Creating modular applications with Express
        6. Bootstrapping an Express application
        7. Understanding Express middleware
          1. Implementing error handling
          2. Using Express middleware
      4. Summary
    10. 3. A JavaScript Primer
      1. Introducing JavaScript types
        1. JavaScript primitive types
      2. Functional object-oriented programming
        1. Functional programming in JavaScript
        2. Understanding scopes in JavaScript
          1. Strict mode
        3. Object-oriented programming in JavaScript
          1. Programming without classes
            1. Creating objects with the new keyword
          2. Programming with classes
            1. Class-based inheritance
      3. Summary
    11. 4. Introducing Node.js Modules
      1. Organizing your codebase
        1. JavaScript module systems
      2. Creating modules in Node.js
        1. Declaring a module with a name and its own scope
        2. Defining functionality provided by the module
        3. Importing a module into another script
      3. Defining a directory-level module
      4. Implementing an Express middleware module
      5. Summary
    12. 5. Creating Dynamic Websites
      1. Handling user-submitted data
      2. Communicating via Ajax
      3. Implementing other data operations
        1. Listing data in views
        2. Issuing a delete request from the client
        3. Splitting up Express views using partials
      4. Summary
    13. 6. Testing Node.js Applications
      1. Writing a simple test in Node.js
      2. Structuring the codebase for tests
      3. Writing BDD-style tests with Mocha
        1. Resetting state between tests
      4. Using Chai for assertions
      5. Creating test doubles
        1. Creating test doubles using Sinon.JS
      6. Testing an Express application
        1. Simplifying tests using SuperAgent
      7. Full-stack testing with PhantomJS
      8. Summary
    14. 7. Setting up an Automated Build
      1. Setting up an integration server
        1. Setting up a public GitHub repository
        2. Building a project on Travis CI
      2. Automating the build process with Gulp
        1. Running tests using Gulp
      3. Checking code style with ESLint
        1. Automatically fixing issues in ESLint
        2. Running ESLint from Gulp
      4. Gathering code coverage statistics
      5. Running integration tests from Gulp
      6. Summary
    15. 8. Mastering Asynchronicity
      1. Using the callback pattern for asynchronous code
        1. Exposing the callback pattern
        2. Consuming asynchronous interfaces
      2. Writing cleaner asynchronous code using promises
        1. Implementing promise-based asynchronous code
          1. Consuming the promise pattern
        2. Parallelising operations using promises
      3. Combining asynchronous programming patterns
      4. Summary
    16. 9. Persisting Data
      1. Introducing MongoDB
        1. Why choose MongoDB?
          1. Object modeling
          2. JavaScript
          3. Scalability
        2. Getting started with MongoDB
          1. Using the MongoDB shell
      2. Using MongoDB with Express
        1. Persisting objects with Mongoose
        2. Isolating persistence code
        3. Dependency injection in Node.js
        4. Providing dependencies
        5. Running database integration tests on Travis CI
      3. Introducing Redis
        1. Why use Redis?
        2. Installing Redis
        3. Using Redis as a key-value store
        4. Storing structured data in Redis
      4. Building a user ranking system with Redis
        1. Using Redis from Node.js
          1. Testing with redis-js
        2. Implementing user rankings with Redis
        3. Making use of the users service
      5. A note on security
      6. Summary
    17. 10. Creating Real-time Web Apps
      1. Understanding options for real-time communication
      2. Introducing Socket.IO
        1. Implementing a chat room with Socket.IO
      3. Scaling real-time Node.js applications
        1. Using Redis as a backend
      4. Integrating Socket.IO with Express
      5. Directing Socket.IO messages
      6. Testing Socket.IO applications
      7. Organizing Socket.IO applications
        1. Exposing real-time updates to the model
        2. Organizing Socket.IO applications using namespaces
        3. Partitioning Socket.IO clients using rooms
      8. Summary
    18. 11. Deploying Node.js Applications
      1. Working with Heroku
        1. Setting up a Heroku account and tooling
        2. Running an application locally with Heroku
        3. Deploying an application to Heroku
        4. Working with Heroku logs, config, and services
          1. Setting up MongoDB
          2. Setting up Redis
      2. Deploying from Travis CI
        1. Setting encrypted Travis CI environment variables
          1. Installing Ruby
          2. Creating an encrypted environment variable
      3. Further resources
      4. Summary
    19. 12. Authentication in Node.js
      1. Introducing Passport
        1. Choosing an authentication strategy
        2. Understanding third-party authentication
      2. Using Express sessions
        1. Specifying a session secret
        2. Deciding when the session gets saved
        3. Using alternative session stores
        4. Using session middleware
      3. Implementing social login
        1. Setting up a Twitter application
        2. Configuring Passport
        3. Persisting user data with Redis
        4. Configuring Passport with persistence
        5. Hiding functionality from unauthenticated users
        6. Integration testing with Passport
      4. Allowing users to log out
      5. Adding other login providers
      6. Summary
    20. 13. Creating JavaScript Packages
      1. Writing universal modules
        1. Comparing Node.js and RequireJS
        2. Supporting the browser environment
        3. Using AMD modules with RequireJS
        4. Isomorphic JavaScript
      2. Writing npm packages
        1. Defining an npm package
      3. Publishing a package to npm
        1. Running automated clients on the web
        2. Releasing a standalone tool to npm
      4. Using Node.js modules in the browser
        1. Controlling Browserify's output
      5. Summary
    21. 14. Node.js and Beyond
      1. Understanding Node.js versioning
        1. A brief history of Node.js
        2. Introducing the Node.js LTS schedule
      2. Understanding ECMAScript versioning
      3. Exploring ECMAScript 2015
        1. Understanding ES2015 modules
        2. Using syntax improvements from ES2015
          1. The for... of loop
          2. The spread operator and rest parameters
          3. Destructuring assignment
        3. Introducing generators
      4. Introducing ECMAScript 2016
      5. Going beyond JavaScript
        1. Exploring compile-to-JavaScript languages
          1. TypeScript
          2. CoffeeScript
          3. And beyond...
        2. Introducing a true assembly language for the web
          1. Understanding asm.js
          2. Understanding WebAssembly
      6. JavaScript and ASP.NET
        1. Exploring .NET Core
          1. Defining project structure in .NET Core
          2. Managing dependencies in .NET Core
          3. Building web applications in ASP.NET Core
        2. Integration with JavaScript
          1. Server-side JavaScript integration with .NET
      7. Summary
    22. Index