Posts

Showing posts from July 8, 2018

Node.js URL Module

<!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> Node.js URL Module ❮ Previous Next ❯ The Built-in URL Module The URL module splits up a web address into readable parts. To include the URL module, use the require() method: var url = require('url'); Parse an address with the url.parse() method, and it will return a URL object with each part of the address as properties: Example Split a web address into readable parts: var url = require('url'); var adr = 'http://localhost:8080/default.htm?year=2017&month=february'; var q = url.parse(adr, true); console.log(q.host); //returns 'localhost:8080' console.log(q.pathname); //returns '/default.htm' console.log(q.search); //returns '?year=2017&month=february' var qdata = q.query; //returns an object: { year: 2017, month: 'february' } console.log(qdata.month); //returns 'february' Run example

Node.js File System Module

<!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> Node.js File System Module ❮ Previous Next ❯ Node.js as a File Server The Node.js file system module allow you to work with the file system on your computer. To include the File System module, use the require() method: var fs = require('fs'); Common use for the File System module: Read files Create files Update files Delete files Rename files Read Files The fs.readFile() method is used to read files on your computer. Assume we have the following HTML file (located in the same folder as Node.js): demofile1.html <html> <body> <h1>My Header</h1> <p>My paragraph.</p> </body> </html> Create a Node.js file that reads the HTML file, and return the content: Example var http = require('http'); var fs = require('fs'); http.createServer(function (req, res) {   fs.readFile('demofile1.html&

Node.js HTTP Module

googletag.cmd.push(function() { googletag.display('div-gpt-ad-1422003450156-2'); }); Node.js HTTP Module ❮ Previous Next ❯ The Built-in HTTP Module Node.js has a built-in module called HTTP, which allows Node.js to transfer data over the Hyper Text Transfer Protocol (HTTP). To include the HTTP module, use the require() method: var http = require('http'); Node.js as a Web Server The HTTP module can create an HTTP server that listens to server ports and gives a response back to the client. Use the createServer() method to create an HTTP server: Example var http = require('http'); //create a server object: http.createServer(function (req, res) {   res.write('Hello World!'); //write a response to the client   res.end(); //end the response }).listen(8080); //the server object listens on port 8080 Run example » The function passed into the http.createServer() method, will be executed when someon

Node.js Modules

googletag.cmd.push(function() { googletag.display('div-gpt-ad-1422003450156-2'); }); Node.js Modules ❮ Previous Next ❯ What is a Module in Node.js? Consider modules to be the same as JavaScript libraries. A set of functions you want to include in your application. Built-in Modules Node.js has a set of built-in modules which you can use without any further installation. Look at our Built-in Modules Reference for a complete list of modules. Include Modules To include a module, use the require() function with the name of the module: var http = require('http'); Now your application has access to the HTTP module, and is able to create a server: http.createServer(function (req, res) {     res.writeHead(200, {'Content-Type': 'text/html'});     res.end('Hello World!'); }).listen(8080); Create Your Own Modules You can create your own modules, and easily include them in your applications. The fo

Node.js Get Started

<!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> Node.js Get Started ❮ Previous Next ❯ Download Node.js The official Node.js website has installation instructions for Node.js: https://nodejs.org Getting Started Once you have downloaded and installed Node.js on your computer, lets try to display "Hello World" in a web browser. Create a Node.js file named "myfirst.js", and add the following code: myfirst.js var http = require('http'); http.createServer(function (req, res) {     res.writeHead(200, {'Content-Type': 'text/html'});     res.end('Hello World!'); }).listen(8080); Save the file on your computer: C:Users Your Name myfirst.js The code tells the computer to write "Hello World!" if anyone (e.g. a web browser) tries to access your computer on port 8080. For now, you do not have to understand the code. It will be explained later. Command Line Interface N

Node.js Introduction

<!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> Node.js Introduction ❮ Previous Next ❯ What is Node.js? Node.js is an open source server environment Node.js is free Node.js runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) Node.js uses JavaScript on the server Why Node.js? Node.js uses asynchronous programming! A common task for a web server can be to open a file on the server and return the content to the client. Here is how PHP or ASP handles a file request: Sends the task to the computer's file system. Waits while the file system opens and reads the file. Returns the content to the client. Ready to handle the next request. Here is how Node.js handles a file request: Sends the task to the computer's file system. Ready to handle the next request. When the file system has opened and read the file, the server returns the content to the client. Node.js eliminates the waiting, and

Node.js Tutorial

<!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> Node.js Tutorial ❮ Home Next ❯ Node.js is an open source server environment. Node.js allows you to run JavaScript on the server. Start learning Node.js now » Learning by Examples Our "Show Node.js" tool makes it easy to learn Node.js, it shows both the code and the result. Example var http = require('http'); http.createServer(function (req, res) {     res.writeHead(200, {'Content-Type': 'text/plain'});     res.end('Hello World!'); }).listen(8080); Run example » Click on the "Run example" button to see how it works. Examples Running in the Command Line Interface In this tutorial there will be some examples that are better explained by displaying the result in the command line interface. When this happens, The "Show Node.js" tool will show the result in a black screen on the right: Example console.log('Th

ADO Data Types

<!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> ADO Data Types ❮ Previous Next ❯ The table below shows the ADO Data Type mapping between Access, SQL Server, and Oracle: DataType Enum Value Access SQLServer Oracle adBigInt 20   BigInt (SQL Server 2000 +)   adBinary 128   Binary TimeStamp Raw * adBoolean 11 YesNo Bit   adChar 129   Char Char adCurrency 6 Currency Money SmallMoney   adDate 7 Date DateTime   adDBTimeStamp 135 DateTime (Access 97 (ODBC)) DateTime SmallDateTime Date adDecimal 14     Decimal * adDouble 5 Double Float Float adGUID 72 ReplicationID (Access 97 (OLEDB)), (Access 2000 (OLEDB)) UniqueIdentifier (SQL Server 7.0 +)   adIDispatch 9       adInteger 3 AutoNumber Integer

ADO Stream Object

googletag.cmd.push(function() { googletag.display('div-gpt-ad-1422003450156-2'); }); ADO Stream Object ❮ Previous Next ❯ Stream Object (ADO version 2.5) The ADO Stream Object is used to read, write, and manage a stream of binary data or text. A Stream object can be obtained in three ways: From a URL pointing to a document, a folder, or a Record object By instantiating a Stream object to store data for your application By opening the default Stream object associated with a Record object Syntax objectname.property objectname.method Properties Property Description CharSet Sets or returns a value that specifies into which character set the contents are to be translated. This property is only used with text Stream objects (type is adTypeText) EOS Returns whether the current position is at the end of the stream or not LineSeparator Sets or returns the line separator character used

ADO Recordset Object

googletag.cmd.push(function() { googletag.display('div-gpt-ad-1422003450156-2'); }); ADO Recordset Object ❮ Previous Next ❯ Examples GetRows This example demonstrates how to use the GetRows method. Recordset Object The ADO Recordset object is used to hold a set of records from a database table. A Recordset object consist of records and columns (fields). In ADO, this object is the most important and the one used most often to manipulate data from a database. ProgID set objRecordset=Server.CreateObject("ADODB.recordset") When you first open a Recordset, the current record pointer will point to the first record and the BOF and EOF properties are False. If there are no records, the BOF and EOF property are True. Recordset objects can support two types of updating:  Immediate updating - all changes are written immediately to the database once you call the Update method. Batch updating - the provider will cache m

ADO Record Object

googletag.cmd.push(function() { googletag.display('div-gpt-ad-1422003450156-2'); }); ADO Record Object ❮ Previous Next ❯ Record Object (ADO version 2.5) The ADO Record object is used to hold a row in a Recordset, a directory, or a file from a file system. Only structured databases could be accessed by ADO in versions prior 2.5. In a structured database, each table has the exact same number of columns in each row, and each column is composed of the same data type. The Record object allows access to data-sets where the number of columns and/or the data type can be different from row to row.  Syntax objectname.property objectname.method Properties Property Description ActiveConnection Sets or returns which Connection object a Record object belongs to Mode Sets or returns the permission for modifying data in a Record object ParentURL Returns the absolute URL of the parent Record RecordType

ADO Property Object

<!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> ADO Property Object ❮ Previous Next ❯ Property Object The ADO Property object represents a dynamic characteristic of an ADO object that is defined by the provider. Each provider that talks with ADO has different ways of interacting with ADO. Therefore, ADO needs to store information about the provider in some way. The solution is that the provider gives specific information (dynamic properties) to ADO. ADO stores each provider property in a Property object that is again stored in the Properties Collection. The Collection is assigned to either a Command object, Connection object, Field object, or a Recordset object. ProgID set objProperty=Server.CreateObject("ADODB.property") Properties Property Description Attributes Returns the attributes of a Property object Name Sets or returns the name of a Property object Type Returns the ty

ADO Parameter Object

<!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> ADO Parameter Object ❮ Previous Next ❯ Parameter Object The ADO Parameter object provides information about a single parameter used in a stored procedure or query.   A Parameter object is added to the Parameters Collection when it is created. The Parameters Collection is associated with a specific Command object, which uses the Collection to pass parameters in and out of stored procedures and queries. Parameters can be used to create Parameterized Commands. These commands are (after they have been defined and stored) using parameters to alter some details of the command before it is executed. For example, an SQL SELECT statement could use a parameter to define the criteria of a WHERE clause. There are four types of parameters: input parameters, output parameters, input/output parameters and return parameters. Syntax objectname.property objectname.method Properties Property

ADO Field Object

<!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> ADO Field Object ❮ Previous Next ❯ Field Object The ADO Field object contains information about a column in a Recordset object. There is one Field object for each column in the Recordset. ProgID set objField=Server.CreateObject("ADODB.field") Properties Property Description ActualSize Returns the actual length of a field's value Attributes Sets or returns the attributes of a Field object DefinedSize Returns the defined size of a field Name Sets or returns the name of a Field object NumericScale Sets or returns the number of decimal places allowed for numeric values in a Field object OriginalValue Returns the original value of a field Precision Sets or returns the maximum number of digits allowed when representing numeric values in a Field object Status Returns the st

ADO Error Object

<!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> ADO Error Object ❮ Previous Next ❯ Error Object The ADO Error object contains details about data access errors that have been generated during a single operation.  ADO generates one Error object for each error. Each Error object contains details of the specific error, and are stored in the Errors collection. To access the errors, you must refer to a specific connection. To loop through the Errors collection: <% for each objErr in objConn.Errors   response.write("<p>")   response.write("Description: ")   response.write(objErr.Description & "<br>")   response.write("Help context: ")   response.write(objErr.HelpContext & "<br>")   response.write("Help file: ")   response.write(objErr.HelpFile & "<br>")   response.write("Native error: ")   response.write(objEr

ADO Connection Object

<!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> ADO Connection Object ❮ Previous Next ❯ Connection Object The ADO Connection Object is used to create an open connection to a data source. Through this connection, you can access and manipulate a database. If you want to access a database multiple times, you should establish a connection using the Connection object. You can also make a connection to a database by passing a connection string via a Command or Recordset object. However, this type of connection is only good for one specific, single query. ProgID set objConnection=Server.CreateObject("ADODB.connection") Properties Property Description Attributes Sets or returns the attributes of a Connection object CommandTimeout Sets or returns the number of seconds to wait while attempting to execute a command ConnectionString Sets or returns the details used to create a connection

ADO Command Object

<!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> ADO Command Object ❮ Previous Next ❯ Command Object The ADO Command object is used to execute a single query against a database. The query can perform actions like creating, adding, retrieving, deleting or updating records. If the query is used to retrieve data, the data will be returned as a RecordSet object. This means that the retrieved data can be manipulated by properties, collections, methods, and events of the Recordset object. The major feature of the Command object is the ability to use stored queries and procedures with parameters. ProgID set objCommand=Server.CreateObject("ADODB.command") Properties Property Description ActiveConnection Sets or returns a definition for a connection if the connection is closed, or the current Connection object if the connection is open CommandText Sets or returns a provider command CommandTimeout

ADO Speed Up With GetString()

googletag.cmd.push(function() { googletag.display('div-gpt-ad-1422003450156-2'); }); ADO Speed Up With GetString() ❮ Previous Next ❯ Use the GetString() method to speed up your ASP script (instead of using multiple Response.Write's). Multiple Response.Write's The following example demonstrates one way of how to display a database query in an HTML table: <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open "c:/webdata/northwind.mdb" set rs = Server.CreateObject("ADODB.recordset") rs.Open "SELECT Companyname, Contactname FROM Customers", conn %> <table border="1" width="100%"> <%do until rs.EOF%>   <tr>     <td><%Response.Write(rs.fields("Companyname"))%></td>     <td><%Response.Write(rs.fields("Contactname"

ADO Demonstration

<!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> ADO Demonstration ❮ Previous Next ❯ To demonstrate a small real life ADO application, we have put together a few ADO demos. Read this First If you try to update the database, you will get the error message: "You do not have permission to update this database". You get this error because you don't have write access to our server. BUT, if you copy the code and run it on your own system, you might get the same error. That is because the system might see you as an anonymous internet user when you access the file via your browser. In that case, you have to change the access-rights to get access to the file. How to change the access-rights of your Access database? Open Windows Explorer, find the .mdb file. Right-click on the .mdb file and select Properties. Go to the Security tab and set the access-rights here. List, Edit, Update, and Delete Database Records List, e

ADO Delete Records

googletag.cmd.push(function() { googletag.display('div-gpt-ad-1422003450156-2'); }); ADO Delete Records ❮ Previous Next ❯ We may use the SQL DELETE command to delete a record in a table in a database.  Delete a Record in a Table We want to delete a record in the Customers table in the Northwind database. We first create a table that lists all records in the Customers table: <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open "c:/webdata/northwind.mdb" set rs=Server.CreateObject("ADODB.Recordset") rs.open "SELECT * FROM customers",conn %> <h2>List Database</h2> <table border="1" width="100%"> <tr> <% for each x in rs.Fields   response.write("<th>" & ucase(x.name) & "</th>") next %> </tr> <% do until

ADO Update Records

googletag.cmd.push(function() { googletag.display('div-gpt-ad-1422003450156-2'); }); ADO Update Records ❮ Previous Next ❯ We may use the SQL UPDATE command to update a record in a table in a database.  Update a Record in a Table We want to update a record in the Customers table in the Northwind database. We first create a table that lists all records in the Customers table: <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open "c:/webdata/northwind.mdb" set rs=Server.CreateObject("ADODB.Recordset") rs.open "SELECT * FROM customers",conn %> <h2>List Database</h2> <table border="1" width="100%"> <tr> <% for each x in rs.Fields   response.write("<th>" & ucase(x.name) & "</th>") next %> </tr> <% do until

ADO Add Records

<!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> ADO Add Records ❮ Previous Next ❯ We may use the SQL INSERT INTO command to add a record to a table in a database.  Add a Record to a Table in a Database We want to add a new record to the Customers table in the Northwind database. We first create a form that contains the fields we want to collect data from: <html> <body> <form method="post" action="demo_add.asp"> <table> <tr> <td>CustomerID:</td> <td><input name="custid"></td> </tr><tr> <td>Company Name:</td> <td><input name="compname"></td> </tr><tr> <td>Contact Name:</td> <td><input name="contname"></td> </tr><tr> <td>Address:</td> <td><input name="address"></td> </tr><t

ADO Sort

googletag.cmd.push(function() { googletag.display('div-gpt-ad-1422003450156-2'); }); ADO Sort ❮ Previous Next ❯ We may use SQL to specify how to sort the data in the record set.  Sort the Data We want to display the "Companyname" and "Contactname" fields from the "Customers" table, ordered by "Companyname" (remember to save the file with an .asp extension): Example <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open "c:/webdata/northwind.mdb" set rs = Server.CreateObject("ADODB.recordset") sql="SELECT Companyname, Contactname FROM Customers ORDER BY CompanyName" rs.Open sql, conn %> <table border="1" width="100%">   <tr>   <%for each x in rs.Fields     response.write("<th>" & x.name & "</th&