O'Reilly logo

The Node Craftsman Book by Manuel Kiessling

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Making SQL queries secure against attacks

Let's now go full circle and create a simple web application that allows to insert data into our table and also reads and displays the data that was entered.

We need to start a web server with two routes (one for displaying data, one for taking user input), and we need to pass user input to the database and database results to the webpage. Here is the application in one go:

 'use strict'; var mysql = require('mysql'), http = require('http'), url = require('url'), querystring = require('querystring'); // Start a web server on port 8888. Requests go to function handleRequest http.createServer(handleRequest).listen(8888); // Function that handles http requests function handleRequest(request, response) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required