Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
188 views

Node - Js and Web Application Development: Ali Ahmed, Matt Stevens

Node.js is a JavaScript runtime environment that allows building fast and scalable network applications. The document discusses Node.js and how to create a basic web server using it in NetBeans. It covers installing Node.js, creating a server that handles requests and responses, organizing the code, and using modules to reuse code and add functionality like displaying dates. The tutorial demonstrates building a simple web server project in NetBeans to get started with Node.js and handling HTTP requests.

Uploaded by

Vinodh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
188 views

Node - Js and Web Application Development: Ali Ahmed, Matt Stevens

Node.js is a JavaScript runtime environment that allows building fast and scalable network applications. The document discusses Node.js and how to create a basic web server using it in NetBeans. It covers installing Node.js, creating a server that handles requests and responses, organizing the code, and using modules to reuse code and add functionality like displaying dates. The tutorial demonstrates building a simple web server project in NetBeans to get started with Node.js and handling HTTP requests.

Uploaded by

Vinodh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Node.

js and Web Application


Development
Ali Ahmed, Matt Stevens
Agenda

Back-end Applications
What is Node.js? Web Framework

Node.js is:
1. Fast
2. Can handle tons of concurrent requests
3. Guess what? Written in JavaScript.
Important things to remember
when using Node.js
Install Node.js
http://nodejs.org
Verify your installation

Check version:
node -v

node -e “console.log(new Date());”


Good all in all tutorial
• https://www.youtube.com/watch?v=UqDuhvDFc7A
• Using NetBeans and Express framework
Node.js Built-in Modules
• To include a module, use the require() function with the name of the
module.

• Example
• var http = require('http');
Create Your Own Modules
• Create a module that returns the current date and time
• exports.myDateTime = function () {
return Date();
};

myfirstmodule.js
Tutorial: How to Create Your Own Web Server
NetBeans Project
Tutorial: How to Create Your Own Web Server

NetBeans Project
Creating the Server
1. Importing the required modules
• var http = require('http');
2. Specifying the server settings
• var hostname = '127.0.0.1';
• var port = 3000;
3. Creating the Server
• var server = http.createServer(function (request, response) {
displayWelcomePage(response);});
4. Writing a response/HTML back
5. Start your server
Creating the Server
4. Writing a Response Back

function displayWelcomePage(response)
{
console.log('connection established. Loading the login form....');
response.write('Welcome, this is you first Node.js connection');
response.end();
}
Creating the Server
5. Start your server

server.listen( port, hostname);


console.log('Server running at http://'+hostname+':'+port+'/');
Adding/Using Your Own Module

Myfirstmodule.js

Wherever you want to use:

md.myDateTime()
Organise your code better
var server = http.createServer( function (request, response) {
if (request.method.toLowerCase() == 'get'){
displayForm(response);
}
else if (request.method.toLowerCase() == 'post') {
console.log('post method called');
response.write('Done');
response.end();
}
}
);
Node.js and HTML Response
• Writing html back
• var fs = require('fs');
• Dealing with forms
• var formidable = require("formidable");
• var util = require('util');
Complete NetBeans Project

Have fun!!

You might also like