In this article, we are going to see how to create a table in sqlite3 database using node.js. So for this, we are going to use the run function which is available in sqlite3.
SQLite is a self-contained, high-reliability, embedded, public-domain, SQL database engine. It is the most used database engine in the world. Let’s understand How to create a table in a sqlite3 database using Node.js.
Below is the step by step implementation:
Step 1: Setting up the NPM package of the project using the following command:
npm init -y
Step 2: Install Dependencies using the following command:
npm install express sqlite3
Project structure: It will look like the following.
Step 3: Here, we created a basic express server that renders GeeksforGeeks on the browser screen.
Step 4: Importing ‘sqlite3’ into our project using the following syntax. There are lots of features in the sqlite3 module
const sqlite3 = require('sqlite3');
Step 5: Now write a query for creating a table in sqlite3.
var query = 'CREATE TABLE GFG ( ID NUMBER , USER VARCHAR(100 ));'
Step 6: Here we are going to use a Run method which is available in sqlite3 which helps us to run queries.
Step to Run Server: Run the server using the following command from the root directory of the project:
node index.js
Output:
Reference: https://www.npmjs.com/package/sqlite3