NODEJS

Node.js HTTP Module

Node.js HTTP Module

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…
Read More
MySQL Create Table

MySQL Create Table

Creating a Table To create a table in MySQL, use the "CREATE TABLE" statement. Make sure you define the name of the database when you create the connection: Example Create a table named "customers": var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: "yourusername", password: "yourpassword",   database: "mydb" }); con.connect(function(err) { if (err) throw err; console.log("Connected!"); var sql = "CREATE TABLE customers (name VARCHAR(255), address VARCHAR(255))"; con.query(sql, function (err, result) { if (err) throw err; console.log("Table created"); }); }); Run example » Save the code above in a file called "demo_create_table.js" and run the file: Run "demo_create_table.js"…
Read More
Node.js Upload Files

Node.js Upload Files

  The Formidable Module There is a very good module for working with file uploads, called "Formidable". The Formidable module can be downloaded and installed using NPM: C:UsersYour Name>npm install formidable After you have downloaded the Formidable module, you can include the module in any application: var formidable = require('formidable'); Upload Files Now you are ready to make a web page in Node.js that lets the user upload files to your computer: Step 1: Create an Upload Form Create a Node.js file that writes an HTML form, with an upload field: Example This code will produce an HTML form: var http…
Read More
No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.