Installing

The Node.js libraries for DataTables can be installed with npm, or a compatible package manager.

npm installation

npm is a dependency and package manager for Node.js which can be used to easily manage and install external libraries such as DataTables's Node.js libraries. Install the DataTables Node.js libraries using:

npm install datatables.net-editor-server

Then, in the file (Javascript or Typescript) where you wish to use the libraries, you import them:

import {DataTable, Column, Editor, Field} from 'datatables.net-editor-server';

Database connection

The next step is to set up the database connection so the libraries can interact with the server, reading and modified data as required. This is done with Knex.js. The Knex.js documentation does an excellent job of explaining its own connection options - you essentially just need to create a Knex connection and pass that on to the DataTables Node.js libraries to use.

A sample configuration might look like:

import knex from 'knex';

const db = knex({
    client: 'mysql', // pg, mssql, etc

    connection: {
        database:    '...',
        host:        '...',
        password:    '...',
        user:        '...',
        dateStrings: true
    }
});

export default db;

This is typically done in its own file (e.g. db.js) so you can import that file from any other, allowing the database connection to be configured from a single location.

Sources

If you are interested in using the Node.js libraries directly from its git repository, you can find it on Github. The DataTables Node.js source is released under the MIT license.

TypeScript

It is worth noting that the DataTables Node.js libraries are written in TypeScript and transpiled to generic Javascript. As such, when you include datatables.net-editor-server in your software, if you are using TypeScript you will automatically get the benefits of type checking that TypeScript offers (and code completion if your code editor supports that). If you are not using TypeScript, you won't notice anything different!

Next steps

With the server-side package installed, imported into your file and a database connection, we can move on to working with the libraries!