万本电子书0元读

万本电子书0元读

顶部广告

Advanced Node.js Development电子书

售       价:¥

3人正在读 | 0人评论 9.8

作       者:Andrew Mead

出  版  社:Packt Publishing

出版时间:2018-03-30

字       数:63.7万

所属分类:

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Takes you through creating your own API, building a full real-time web app, securing your Node systems, and practical applications of the latest Async and Await technologies. It maps out everything in a comprehensive, easy-to-follow package designed to get you up and running quickly. About This Book ? Entirely project-based and practical ? Explains the "why" of Node.js features, not just the "how", providing with a deep understanding and enabling you to easily apply concepts in your own applications ? Covers the full range of technologies around Node.js – npm, MongoDB, version control with Git, and many more Who This Book Is For This book is for anyone looking to launch their own Node applications, switch careers, or freelance as a Node developer. You should have a basic understanding of JavaScript in order to follow this book. This book follows directly on from Learning Node.js Development, but more advanced readers can benefit from this book without having read the first part. What You Will Learn ? Develop, test, and deploy real-world Node.js applications ? Master Node.js by building practical, working examples ? Use awesome third-party Node modules such as MongoDB, Mongoose, Socket.io, and Express ? Create real-time web applications ? Explore async and await in ES7 In Detail Advanced Node.js Development is a practical, project-based book that provides you with all you need to progress as a Node.js developer. Node is a ubiquitous technology on the modern web, and an essential part of any web developer’s toolkit. If you're looking to create real-world Node applications, or you want to switch careers or launch a side-project to generate some extra income, then you're in the right place. This book was written around a single goal: turning you into a professional Node developer capable of developing, testing, and deploying real-world production applications. There's no better time to dive in. According to the 2018 Stack Overflow Survey, Node is in the top ten for back-end popularity and back-end salary. This book is built from the ground up around the latest version of Node.js (version 9.x.x). You'll be learning all the cutting-edge features available only in the latest software versions. This book delivers advanced skills that you need to become a professional Node developer. Along this journey you'll create your own API, you'll build a full real-time web app and create projects that apply the latest Async and Await technologies. Andrew Mead maps everything out for you in this book so that you can learn how to build powerful Node.js projects in a comprehensive, easy-to-follow package designed to get you up and running quickly. Style and approach This book is entirely project-based. From the very beginning, you'll be programming every single app and completing various challenges designed to help test and reinforce what you've learned. There's no copying-and-pasting here. This book is about writing code and building projects.
目录展开

Title Page

Copyright and Credits

Advanced Node.js Development

Packt Upsell

Why subscribe?

PacktPub.com

Contributors

About the author

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images

Conventions used

Get in touch

Reviews

Getting Set Up

Installing MongoDB and Robomongo for Linux and macOS

Installing MongoDB and Robomongo for Windows

Creating and reading data

Summary

MongoDB, Mongoose, and REST APIs – Part 1

Connecting to MongoDB and writing data

Creating a directory for the project

Connecting the mongodb-connect file to the database

Adding a string as the first argument

Adding the callback function as the second argument

Error handling in mongodb-connect

Running the file in the Terminal

Adding data to the database

Adding a new record into a collection

The ObjectId

The _id property in the context of MongoDB

Calling the .getTimestamp function

Using object destructuring ES6

Creating a new instance of objectID

Fetching data

Fetching todos in Robomongo file

The find method

Writing a query to fetch certain values

Writing a query to fetch completed todos

Qureying todos by id

Implementing the count method

Querying users collection

Setting up the repo

Deleting documents

Exploring methods to delete data

The deleteMany method

The deleteOne Method

The deleteOne method

The findOneAndDelete method

Using the deleteMany and findOneAndDelete methods

Removing duplicate documents

Targeting the documents using ID

Running the findOneAndDelete and deleteMany statements

Making commit for the deleting documents methods

Updating data

Summary

MongoDB, Mongoose, and REST APIs – Part 2

Setting up Mongoose

Setting up root of the project

Connecting mongoose to database

Creating the todo model

Creating a brand-new Todo

Saving the instance to the database

Running the Todos script

Creating a second Todo model

Validators, Types, and Defaults

Mongoose validators

Customizing the Todo text property

Mongoose defaults

Mongoose types

Creating a Mongoose user model for authentication

Setting up the email property

Installing Postman

Making an HTTP request to Google

Illustrating working of the JSON data

Resource Creation Endpoint - POST /todos

Refactoring the server.js file to create POST todos route

Configuring the Todo and Users file

Loading Todo and User file in server.js

Configuring the Express application

Configuring the POST route

Getting body data from the client

Creating an instance of Mongoose model

Setting up HTTP status code

Testing POST /todos inside of Postman

Adding more Todos to the database

Testing POST /todos

Installing npm modules for testing POST /todos route

Setting up the test files

Loading the test files

Adding describe block for the test cases

Making the POST requests via supertest

Making assertions about the POST request

Making a request to fetch the Todos from the database

Adding the catch call for the error handling

Setting up test scripts in package.json

Adding testing life cycle method in server.test.js file

Running the test suite

Test case: should not create todo with invalid body data

Making assertions about the length of the Todos collection

Making commit for POST /todos route

List Resources - GET /todos

Creating the GET /todos route

Testing the GET /todos route

Setting up Post request to create a todo

Testing GET /todos

Adding seed data for the GET /todos test case

Adding a describe block to the test case

Adding assertions to the test case

Summary

MongoDB, Mongoose, and REST APIs – Part 3

Mongoose queries and ID validation

Todo.find method

Todo.findOne method

Todo.findById method

Handling situations where the ID doesn't exist

Validating an ObjectID

Getting an individual resource – GET /todos/:id

Taking on the challenge

Challenge step 1 - filling the code

Challenge step 2 - Making the query

challenge step 3 - success path

Testing GET /todos/:id

Writing test cases for GET/todos/:id

Test 1 - Super test request

Test 2 - Verifying invalid ID

Test 3 - Validating invalid ObjectID

Deploying the API to Heroku

Creating a Heroku app

Heroku logs

Postman environments

Managing Postman environments

Todo App Local environment

Todo App Heroku environment

Deleting a resource – DELETE /todos/:id

Todo.remove method

Todo.findOneAndRemove method

Todo.findByIdAndRemove method

Creating a delete route

Testing DELETE /todos/:id

Test case 1 - should remove a todo

Test case 2 - should return 404 if todo not found

Test case 3 - should return 404 if object id is invalid

Test case 4 - should return 404 if todo not found

Updating a Resource - PATCH /todos/:id

Installing Lodash library

Testing Todos for the patch call

Testing PATCH /todos/:id

Test 1 - To complete the incomplete todo

Test 2 - to make complete todo incomplete

Creating a Test database

Summary

Real-Time Web Apps with Socket.io

Creating a new web app project

Setting up our basic app structure

Setting up the index.html file for DOCTYPE

Setting up the server.js file for the public directory

The join method

Configuring basic server setup

Setting up a gitignore file

Making a commit with the current uncommitted files

Adding Socket.io to an app

Setting up Socket.io

Creating a server using the http library

Configuring the server to use Socket.io

Communication between the client and server

The io.on method

Adding a connection event in the client

The disconnect event

Emitting and listening to custom events

Creating custom events inside an application

Moving the JavaScript into a separate file

Adding a newEmail custom event

The emit method

Testing the newEmail event

Adding a createEmail custom event

socket.emit in the developer console

The custom events in the chat app

The newMessage event

Broadcasting events

Wiring up the createMessage listener for all users

Testing the messaging events

Committing and deploying messaging to Heroku

Testing messaging in a Firefox browser using Heroku

Broadcasting events to other users

Emitting two events when a user connects

Greeting an individual user

Broadcasting a new user in the chat

Testing the user connection

Summary

Generating newMessage and newLocationMessage

Message generator and tests

Generating the newMessage object using the utility function

Writing test cases

Adding the test-watch script

Adding the test script

Running the test suite for the message utility

Integrate the utility function into our application

Event acknowledgements

Setting up acknowledgements

Sending an acknowledgement from server to the client

Updating the event emitter

Updating the event listener

The message form and jQuery

Using the jQuery library

Adding the form field in index.html

Setting up the form tag

Adding the text field

Testing the form's rendering

Using jQuery to select element

Adding the selector element to index.js

Testing the update event listener

Rendering incoming messages to the screen

Creating an ordered list to render messages

Using jQuery to create element in index.js

Testing the incoming messages

Making a commit for the message form

Geolocation

Adding the Send Location button to the application

Adding a click listener to the Send Location button

Checking access to the geolocation API

Fetching a user's position

Adding the coordinates object in the users position

Passing coordinates data with the connected users

Rendering clickable link in place of text coordinates

Sorting out the URL structure

Emitting newLoactionMessage

Adding generateLocationMessage in the message.js file

Adding an event listener for newLocationMessage

Adding test case for generateLocationMessage

Adding variables for the test case

Making assertion for generateLocationMessage

Running the test case for generateLocationMessage

Summary

Styling Our Chat Page as a Web App

Styling the chat page

Storing the template styles

Tweaking the structure for alignment

Making user experience improvements

Changing the form submit listener

Updating the input tag

Customizing the Send Location

Updating the button text

Timestamps and formatting with Moment

Timestamps in Node

The Date object

Using Moment for timestamps

The Moment documentation

Formatting date using Moment

The Manipulate section in Moment

Printing message timestamps

Getting the formatted values back from timestamps

Updating the message.js file

Integrating Moment on client

Updating the newMessage property

Updating the newLocationMessage property

Mustache.js

Adding mustache.js to the directory

Creating and rendering template for newMessage

Implementing the Mustache.js rendering method

Getting all the data showing up

Providing a custom structure

Adding the list item tag

Adding the message body tag

Creating template for the newLocation message

Rendering the newLocation template

Autoscrolling

Running a height properties calculation

Creating a new variable to scroll messages to the bottom

Determining the calculation

Taking into account the height of new message

Testing the calculations

Scrolling a user when necessary

Committing the calculation-related changes

Summary

The Join Page and Passing Room Data

Adding a join page

Updating the HTML file

Adding the head tag in the HTML file

Adding the body tag in the HTML file

Adding the form-fields for the chat page

Committing the changes in index.html

Passing room data

Getting data to the server

The params and deparams

Setting up listener in server.js

Defining the isRealString function

Calling the isRealString function in server.js

Adding error handler case in chat.js

Adding test cases for the new validation function

Test case 1 – should reject non-string values

Test case 2 – should reject string with only spaces

Test case 3 – should allow strings with non-space characters

Socket.io rooms

Targeting the specific user

Testing the specific user set up

Summary

ES7 classes

Storing users with ES6 classes – Part I

The ES6 class syntax

Creating the ES6 class for a person

The constructor function

The method function

Adding the users class

Adding the test case for addUser

Adding new instances in the users.test file

Making the assertions for the users call

Running the addUser test case

Adding the removeUser, getUser, and getUserList methods

Adding seed data for the test file

Filling the getUserList

Adding test case for getUserList

Filling the getUser

Test case – should find user

Test case – should not find user

Filling the removeUser method

Test case – should remove a user

Test case – should not remove user

Wiring up user list

Adding People list in the chat room

Adding jQuery to update the DOM

Adding user to the user's list

Adding users with unique ID

Emitting the event to the clients

Testing the users list in the chatroom

Removing users when they leave the chatroom

Updating the users list when someone left the chatroom

Emitting custom message

Rendering the users name to the chatroom

Adding a jQuery to add the users to the list

Rendering the updated People list

Testing the users name in the chatroom

Making a commit for updated users list

Sending messages to room only

Updating the chat.js and server.js files

Emitting event to the individual room

Wiring up createLoactionMessage for individual room

Committing the individual room changes

New feature ideas

Summary

Async/Await Project Setup

Using async/await features in promises

Setting up the getUser project

The array find method

Running the getUser object test

Setting up the getGrades project

Creating grades for the getGrades project

Returning a new promise

Setting up the getStatus project

Resolving the getStatus string

Calculating the average

Returning the template string

Async/await basics

Using the async function

Rejecting an error using the async function

Using the await function

A real-world example

Creating a currency-converter using the async/await function

Exploring APIs for currency exchange rate

Taking advantage of axios inside our application

The getExchangeRate function

The getCountries function

Creating convertCurrencyAlt as the async/await function

Handling errors and awaiting async function

Converting getExchangeRate and getCountries into the async function

Error handling in the async function

Printing an error to the screen

Error handling for the getExchangeRate function

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部