Installation
Before you do coding you must install several library from NPM
To install express
$ npm install --save express
To install mysql
$ npm install --save mysql
To install body parser
$ npm install body-parser
And then create module named connected.js
for connect to database
var mysql = require('mysql');
var con = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'db_movies'
});
module.exports = con;
Then create main file named api.js
and following this code
var express = require('express');
var app = express();
var con = require('./connected');
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.listen(3000);
Your directory look like this