More Related Content


Nodejs getting started

  1. Welcome! Node.js Getting Started <@Triet Ho/>
  2. Objectives • After this seminar, the audiences are able to : • Understand the basic of Node.js and common modules • Create simple Node.js app • Start to learn deeper
  3. Agenda – 1 hours • What is Node.js and how it works • Node.js Installation • Node.js project and module structure • Common packages • Host a nodejs app with PM2
  4. What is Node.js • Compare of JS in browser and Node.js (node apps) Chrome Browser V8 JS Engine HTML + CSS + JS … Node.js Async I/O libuv JS V8 JS Engine Event Loop libuv Node Bindings (socket, http, file system,…) Node Standard Library chrome.exe node.exe
  5. What is Node.js Hello World! • File: demo.js • Run demo.js
  6. What is Node.js Async I/O and Event Loop • Node.js uses an event-driven, non-blocking I/O model • Aka: Callbacks • FileSystem Api as examples:
  7. Installation • Just download and install (included npm tool) • • Or via package-manager for linux family: • • npm: Node Package Manager • Find, share, and reuse packages of code from hundreds of thousands of developers • Npm install <package name> [-g ] • -g: install to global that every node apps can use
  8. Project Structure • Basic structure: • Generate package.json npm init • Advanced structure (use node express for web app): • Express.js (node express): Fast, unopinionated, minimalist web framework for Node.js •
  9. Project Structure package.json • Define app metadata and the starting point • npm start in root app folder will exec node bin/www • npm install in root app will download and install the packages in dependences section • The packages are stored in node_modules folder
  10. Module • Organize code better • The common pattern: • The list of module patterns: •
  11. Common packages • Framework for creating web apps • Express.js: it has a generator to create project, • Template Engines (Rendering UI for node web apps) • EJS • Pug (jade) • Mustache: • Working with asynchronous JS • Assync.js: • Promise (bluebird), • Working with database • Mongoose:, • mysql: • SQL Server:
  12. Host a node app with PM2 • PM2 - production process manager for Node.js applications • with a built-in load balancer • keep applications alive forever • reload them without downtime • and to facilitate common system admin tasks • Install PM2 • pm2 start <startpoint.js> • Ref:
  13. Others • IDE: any text editor, Visual Studio Code, notepad++, net beans… • ES6: ECMAScript 6 (aka ECMAScript 2015) • New features of JavaScript language (and including previous version - ES5) • Tutorial: (new syntax, let, lamda, class, module, promise...) • Unit Test: • get start: sinon • CI: ??? • Flow control: •
  14. Questions?
  15. Cafe!