This project demonstrates a simple CRUD (Create, Read, Update, Delete) application using Node.js, Express, TypeScript, and CouchDB. It includes a script to import data from a CSV file into CouchDB.
Before running this application, ensure you have the following prerequisites installed:
- Node.js (v12 or higher): Download Node.js
- Npm: Install Npm
- Yarn: Install Yarn ( you can easily install it with
npm install -g yarn
) - CouchDB: Install CouchDB
- Git: Install Git
(eventually you can config git with
git config --global user.name "Your Name"
and `git config --global user.email ")
First, you need instance of couchdb on your pc, you can download it here
make sure to check the line install windows service
when installing couchdb (you can uninstall it later)
Follow these steps to install and run the application:
-
Clone this repository:
git clone https://github.com/MehdiSeddik/crud-couchdb-nodejs.git
-
Install the dependencies:
yarn install
-
Setup database
Before running the application, you need to configure the CouchDB connection settings. in the .env file, edit the couchdb url and port according to your couchdb configuration.
To create the databases, head on to http://localhost:5984/_utils/, login with the admin credentials you created when installing couchdb, and create two new databases with the following names:
contacts
andgadm
-
Data import
Warning Please make sure the databases
contacts
andgadm
exist
to import data into the couchDB instance, you can run the following command
yarn imp
it will run a script that parse csv and json files and insert the data into the databases.
To start the application, run the following command:
yarn dev
The application will be accessible at http://localhost:[PORT].
API Endpoints The following API endpoints are available:
Method | Endpoint | Description |
---|---|---|
GET | /contacts | Retrieve all items. |
GET | /contact/:id | Retrieve a specific item by ID. |
POST | /contact | Create a new item. |
PUT | /contact/:id | Update an existing item. |
DELETE | /contact/:id | Delete an item. |
A postman collection is available in the assets folder