Week 04 (Final Project) http://fog.ccsf.edu/~hyip Node.js Week 04 (Final Project) http://fog.ccsf.edu/~hyip.

Slides:



Advertisements
Similar presentations
© 2014 IBM Corporation Empowering the IBM ecosystem Introduction to Developing applications using node.js on Bluemix IBM Ecosystem Development Instructors.
Advertisements

CIS101 Introduction to Computing Week 05. Agenda Your questions CIS101 Survey Introduction to the Internet & HTML Online HTML Resources Using the HTML.
13 February Building a Web Page. Links Links: One always links to an anchor point Every page has an implicit anchor point at the start In addition, can.
RESTful Web Development With Nodejs and Express. REST Stands for REpresentational State Transfer Has the following constraints: ◦Client-Server ◦Stateless.
PhoneGap Development How to make an app using PhoneGap Build ? Presentation By MobilePundits.
An Introduction to Front-end Web Development Tom Perkins.
CS 111 – Oct. 4 Web design –HTML –Javascript Commitment: –This week, read sections 4.3 – 4.5.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
02 | Introduction to Express Framework Stacey Mulcahy | Technical Evangelist Rami Sayar | Technical Evangelist.
Basic HTML swap with AJAX. Lets get our beloved html for our llama site. Open the index.html page and add a class to our navigation links. Then lets add.
Node.JS introduction. What is Node.JS? v8 JavaScript runtime Event driven Non-blocking standard libraries Most APIs speak streams Provides a package manager.
I18n - DateTime ASP.NET MVC. I18n DateTime – EF changes  In model classes, use attributes  DataType(DataType.DateTime)  DataType(DataType.Date)  DataType(DataType.Time)
CMPE 280 Web UI Design and Development August 29 Class Meeting
Introduction to MEAN (JavaScript Full Stack Development)
NodeJS and MEAN cs6320.
Express with Node L. Grewe.
NodeJS.
Introduction to Dynamic Web Programming
Web-Technology Lecture 11.
Node.js Express Web Applications
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Node.js Express Web Services
EXCEPTION HANDLING IN SERVER CLIENT PROGRAMMING
In this session, you will learn about:
Express with Node L. Grewe.
Principles of Software Development
NodeJS and MEAN Prof. L. Grewe.
CMPE 280 Web UI Design and Development October 19 Class Meeting
3 Things Everyone Knows About Node JS That You Don't
Build Better Apps with MEAN.
#05 Web Server (CGI, Node.js)
Week 03 Node.js Week 03
CMPE 280 Web UI Design and Development January 30 Class Meeting
Network Programming Lecture 4: Message Posting
Express with Node L. Grewe. Feature 1 Project structure.
Intro to PHP at Winthrop
CS 174: Server-Side Web Programming January 29 Class Meeting
Web-Technology Lecture 10.
NodeJS coding basics L. Grewe.
Client side & Server side scripting
CMPE 280 Web UI Design and Development January 30 Class Meeting
Abel Sanchez, John R. Williams
Web Programming Language
PHP and Forms.
CMPE 280 Web UI Design and Development January 29 Class Meeting
Web Programming Language
Console Use. Console Use Exit Console Run File.
Week 01 Node.js Week 01
Web Programming Language
Web Service Installation and Configuration
Lecture 17: Web Service and post
Lecture 16: Writing Your Own Web Service
RESTful Web Services.
Lecture 11: Node.JS February 16, 2018 Open twitter page, sphere-e page
Lecture 12: The Fetch Api and AJAx
CSc 337 Lecture 1: post.
Lecture 14: JSON and Web SERVICES
Week 04 Node.js Week 04
Week 02 Node.js Week 02
Week 05 Node.js Week 05
Chengyu Sun California State University, Los Angeles
Building Apps in Azure with only Scripting Skills
CS5220 Advanced Topics in Web Programming Angular – Services
CSc 337 Lecture 18: post.
Chengyu Sun California State University, Los Angeles
MEAN login management CS252.
PHP By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and.
Lecture 15: Writing Your Own Web Service
© 2017, Mike Murach & Associates, Inc.
CMPE 280 Web UI Design and Development August 27 Class Meeting
Presentation transcript:

Week 04 (Final Project) http://fog.ccsf.edu/~hyip Node.js Week 04 (Final Project) http://fog.ccsf.edu/~hyip

Installing Express for final project Create a new directory final_project which is under the nodejs_workspace directory. (mkdir final_project, then cd final_project). Use the npm init command under the new final_project folder to create a package.json file for your application – final_project. npm init NOTE: you can hit RETURN to accept the defaults for most of them, except entry point is app.js: entry point: app.js Install express locally in the nodejs_workspace directory, and save it in the dependencies list: npm install express --save Install body-parser middleware, which is responsible for handling Raw, JSON, URL, and Text encoded form data: NOTE: body-parser is a piece of express middleware that reads a form's input and stores it as a javascript object accessible through `req.body` npm install body-parser --save Install multer middleware, which is responsible for the handling of multipart/form-data: npm install multer --save

Handle get method We are going to use the Form GET method in HTML so as to pass two values. The input will be handled by the router “process_get” inside the file “server.js” Steps to complete the project: Create index.html. Create server.js. Start the server: node server.js Run the program from browser: http://localhost:8081/index.html

Create index.html <html> <head><title>this file is used with server.js</title> </head> <body> <h1>Process get method</h1> <form action="http://127.0.0.1:8081/process_get" method="get"> Your First Name: <input type="text" name="fname"> <br> Your Last Name: <input type="text" name="lname"> <br> <input type="submit" value="Process Get method"> </form> </body> </html>

Create server.js var express = require('express'); var app = express(); app.get('/index.html', function (req, res) { res.sendFile(__dirname + "/index.html"); }); app.get('/process_get', function (req, res) { var response = { fname: req.query.fname, lname: req.query.lname }; console.log(response); // res.end(JSON.stringify(response)); res.json(response); var server = app.listen(8081, function () { console.log('server.js is listening at http://127.0.0.1:8081/index.html or http://localhost:8081/index.html');

Handle post method We are going to use the Form GET method in HTML so as to pass two values. The input will be handled by the router “process_post” inside the file “server.js” Steps to complete the project: Update index.html. Update server.js. Start the server: node server.js Run the program from browser: http://localhost:8081/index.html

Update index.html Add the following codes to the index.html <hr> <h1>Process post method</h1> <form action="http://127.0.0.1:8081/process_post" method="post"> Your First Name: <input type="text" name="fname"> <br> Your Last Name: <input type="text" name="lname"> <br> <input type="submit" value="Process Post method"> </form>

Update server.js Add the following codes to the server.js var bodyParser = require('body-parser'); // creating the application/x-www-form-urlencoded parser var urlenParser = bodyParser.urlencoded({ extended: false}); app.post('/process_post', urlenParser, function (req, res) { var response = { fname: req.body.fname, lname: req.body.lname }; console.log(response); res.end(JSON.stringify(response)); });

References Node.js the Right Way, Jim R. Wilson, The Programatic Bookshelf, ISBN 978-1-937785-73-4 NodeJS: Practical Guide for Beginners, Matthew Gimson, ISBN 978-1- 519354-07-5 Express.js: Node.js Framework for Web Application Development, Daniel Green, ISBN 978-1-530204-06-9 Express.com Tutorials Point The Node Beginner Book, Manuel Kiessling, Leanpub, Link.