1. Trang chủ
  2. » Công Nghệ Thông Tin

Node dot JS Platform Succinctly by Agus Kurniawan

109 291 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 109
Dung lượng 1,89 MB

Nội dung

We can obtain information about Node.js at www.nodejs.org. According to the site, “Node.js is a platform built on Chromes JavaScript runtime for easily building fast, scalable network applications. Node.js uses an eventdriven, nonblocking IO model that makes it lightweight and efficient, perfect for dataintensive realtime applications that run across distributed devices.” I suggest you also read the “What is Node.js” thread for a more indepth Node.js definition. Node.js provides the complete solution for serverside applications, such as web platforms. It can communicate with other systems, like database, LDAP, and any legacy application. There are many scenarios we can implement for Node.js.

1 2 By Agus Kurniawan Foreword by Daniel Jebaraj 3 Copyright © 2014 by Syncfusion Inc. 2501 Aerial Center Parkway Suite 200 Morrisville, NC 27560 USA All rights reserved. mportant licensing information. Please read. This book is available for free download from www.syncfusion.com on completion of a registration form. If you obtained this book from any other source, please register and download a free copy from www.syncfusion.com. This book is licensed for reading only if obtained from www.syncfusion.com. This book is licensed strictly for personal or educational use. Redistribution in any form is prohibited. The authors and copyright holders provide absolutely no warranty for any information provided. The authors and copyright holders shall not be liable for any claim, damages, or any other liability arising from, out of, or in connection with the information in this book. Please do not use this book if the listed terms are unacceptable. Use shall constitute acceptance of the terms listed. SYNCFUSION, SUCCINCTLY, DELIVER INNOVATION WITH EASE, ESSENTIAL, and .NET ESSENTIALS are the registered trademarks of Syncfusion, Inc. Technical Reviewer: Rui Machado Copy Editor: Morgan Cartier Weston, content producer, Syncfusion, Inc. Acquisitions Coordinator: Hillary Bowling, marketing coordinator, Syncfusion, Inc. Proofreader: Morgan Cartier Weston, content producer, Syncfusion, Inc. I 4 Table of Contents The Story behind the Succinctly Series of Books 8 About The Author 10 Chapter 1 Introduction to Node.js 11 What is Node.js? 11 Installation 11 Development Tools 13 Hello World 15 Node.js Module 15 Updating Node.js Version 18 Chapter 2 Basic Node.js Programming 20 Defining Variables 20 Comment 21 Arithmetic Operations 21 Mathematical Functions 23 Comparison Operators 24 Logical Operators 26 Increment and Decrement 27 Decision 27 if… then 27 switch… case 28 Iterations 30 For 30 While 31 Chapter 3 Array 32 5 Creating an Array Object 32 Inserting Data 32 Accessing Data 33 Updating Data 33 Removing Data 33 Chapter 4 JSON 35 Creating a JSON Object 35 Displaying Data 35 Accessing Data 36 Editing Data 39 JSON Array 40 Chapter 5 Functions 44 Creating Function 44 Function with a Returning Value 45 Function with Parameters and a Returning Value 46 Callback Function 47 Chapter 6 String Operations 50 Declaring String Type 50 Concatenating String 50 String to Numeric 51 Numeric to String 52 String Parser 52 Check String Data Length 53 Copy Data 54 Upper and Lower Case Characters 55 Getting String Index 56 Exploring Characters 57 6 Chapter 7 Building Your Own Module 59 Creating a Simple Module 59 Module Class 60 Chapter 8 Error Handling and Logging 62 Error Handling 62 Logging 63 Chapter 9 Events 67 Events Module 67 Getting Started 67 Once Event Listener 68 Remove Events 69 Chapter 10 Web Applications 71 Getting Started 71 Manipulating an HTTP Header 73 Handling Page Requests 75 Working with HTTPS 76 Express.js 81 Installation 82 Getting Started 82 Handling Page Requests 83 Express.js with HTTPS 84 Chapter 11 Socket Programming 86 Socket Module 86 Hello World 86 Client/Server Socket 87 Server Socket 87 Client Socket 89 7 Testing 91 UDP Socket 92 UDP Server 92 UDP Client 93 Testing 94 DNS 95 Chapter 12 Socket.io 96 Getting Started 96 Hello World 96 Socket.io and Express.js 100 Real-Time Monitoring 101 Chapter 13 Database Programming 105 Node.js Module for Database 105 SQLite 105 MongoDB 107 8 The Story behind the Succinctly Series of Books Daniel Jebaraj, Vice President Syncfusion, Inc. taying on the cutting edge As many of you may know, Syncfusion is a provider of software components for the Microsoft platform. This puts us in the exciting but challenging position of always being on the cutting edge. Whenever platforms or tools are shipping out of Microsoft, which seems to be about every other week these days, we have to educate ourselves, quickly. Information is plentiful but harder to digest In reality, this translates into a lot of book orders, blog searches, and Twitter scans. While more information is becoming available on the Internet and more and more books are being published, even on topics that are relatively new, one aspect that continues to inhibit us is the inability to find concise technology overview books. We are usually faced with two options: read several 500+ page books or scour the web for relevant blog posts and other articles. Just as everyone else who has a job to do and customers to serve, we find this quite frustrating. The Succinctly series This frustration translated into a deep desire to produce a series of concise technical books that would be targeted at developers working on the Microsoft platform. We firmly believe, given the background knowledge such developers have, that most topics can be translated into books that are between 50 and 100 pages. This is exactly what we resolved to accomplish with the Succinctly series. Isn’t everything wonderful born out of a deep desire to change things for the better? The best authors, the best content Each author was carefully chosen from a pool of talented experts who shared our vision. The book you now hold in your hands, and the others available in this series, are a result of the authors’ tireless work. You will find original content that is guaranteed to get you up and running in about the time it takes to drink a few cups of coffee. S 9 Free forever Syncfusion will be working to produce books on several topics. The books will always be free. Any updates we publish will also be free. Free? What is the catch? There is no catch here. Syncfusion has a vested interest in this effort. As a component vendor, our unique claim has always been that we offer deeper and broader frameworks than anyone else on the market. Developer education greatly helps us market and sell against competing vendors who promise to “enable AJAX support with one click,” or “turn the moon to cheese!” Let us know what you think If you have any topics of interest, thoughts, or feedback, please feel free to send them to us at succinctly-series@syncfusion.com. We sincerely hope you enjoy reading this book and that it helps you better understand the topic of study. Thank you for reading. Please follow us on Twitter and “Like” us on Facebook to help us spread the word about the Succinctly series! 10 About The Author Agus Kurniawan is a founder of PECollege.net. He is a lecturer and author, and has been a Microsoft MVP since 2004. He has more than 10 years of software development experience, especially for Microsoft technologies, and some related to the Linux platform. You can reach Agus via email at aguskur@hotmail.com and at his blog, http://blog.aguskurniawan.net. [...]... add-apt-repository ppa:chris-lea /node. js sudo apt-get update sudo apt-get install nodejs npm For complete instructions on how to install Node. js for another Linux platform, visit: https://github.com/joyent /node/ wiki/Installing -Node. js- via-package-manager If you are a Windows user, you can install Node. js using the setup file You can download it from the Node. js website, http://nodejs.org/download/ Download... node. js" in blue')); console.log(clc.red('"Hello node. js" in red')); console.log(clc.green('"Hello node. js" in green')); The sample of program output can be seen in Figure 9 17 Figure 9: Program output for Node. js application with cli-color module Updating Node. js Version How do you know the version of Node. js you are working with? You can use a Node. js command to get the information on your Node. js. .. Node. js Module Node. js provides modules to help our development It is possible to cut development time because you don’t need write many lines of code There are a lot of Node. js modules that you can use The list of Node. js modules can be seen here: https://github.com/joyent /node/ wiki/Modules To install Node. js modules, you need the Node Packaged Modules (npm) package manager After installing Node. js, ... is Node. js thread for a more in-depth Node. js definition Node. js provides the complete solution for server-side applications, such as web platforms It can communicate with other systems, like database, LDAP, and any legacy application There are many scenarios we can implement for Node. js Installation Node. js can run on Windows, Linux, and Mac It provides 32-bit and 64-bit platforms To install Node. js. .. update the current version of Node. js Check your Node. js version again after installation is complete 19 Chapter 2 Basic Node. js Programming This chapter will describe some basic Node. js programming Node. js uses the JavaScript language to write code If you have experienced programming in JavaScript, you will find it easier to write Node. js code Defining Variables Node. js has a rule to define variables... version Write this script: node –v This is the output of Node. js script: Figure 10: Getting the current Node. js version Node. js doesn’t automatically update the existing runtime You should check and update the Node. js version manually Download the setup file from the Node. js website and then install it on your computer 18 The setup installation will check the installed Node. js If it was found, it will...Chapter 1 Introduction to Node. js What is Node. js? We can obtain information about Node. js at www.nodejs.org According to the site, Node. js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications Node. js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient,... your platform Run it and you will get the setup dialog as follows: 11 Figure 1: A Node. js Setup dialog Follow the installation instructions A Node. js icon will be created on the Windows menu after installation If you click this menu, the Node. js console will open Figure 2: Node. js console 12 You can run the Node. js console manually from Windows Command Prompt (CMD) Launch it and type the following: node. .. code Now how about Node. js? Let’s start writing “hello world” for Node. js First, run your code editor and write the following: console.log('Hello world, nodejs'); Save this code to a file named helloworld .js Then open CMD or Terminal (Linux) and execute this file: node helloworld .js Here is the sample output of our “hello world” application: Figure 6: “Hello world” application for Node. js Note: console.log()... further information about JSON, you can visit the official JSON website, http://www.json.org Creating a JSON Object A JSON object in Node. js uses {} syntax to declare the JSON data type For instance, we have a JSON object called customer This object has the attributes name, email, age and registeredDate The following is an illustration code to declare the customer variable as JSON data var customer = . listed terms are unacceptable. Use shall constitute acceptance of the terms listed. SYNCFUSION, SUCCINCTLY, DELIVER INNOVATION WITH EASE, ESSENTIAL, and .NET ESSENTIALS are the registered trademarks. Weston, content producer, Syncfusion, Inc. I 4 Table of Contents The Story behind the Succinctly Series of Books 8 About The Author 10 Chapter 1 Introduction to Node.js 11 What is. Programming 105 Node.js Module for Database 105 SQLite 105 MongoDB 107 8 The Story behind the Succinctly Series of Books Daniel Jebaraj, Vice President Syncfusion, Inc. taying on the cutting

Ngày đăng: 12/07/2014, 17:20

TỪ KHÓA LIÊN QUAN