Form-Data-To-Postgres
is a Node.js API designed to simplify the process of receiving client contact form submissions and persisting them in a PostgreSQL database. This backend service validates the received data from the client-side and stores it securely in a database for further processing or analysis. It's a robust and efficient way to manage user-generated data coming from web forms.
- Installation
- Usage
- API Endpoints
- Configuration
- Database Setup
- Error Handling
- Contributing
- License
- Acknowledgments
-
Clone the repository to your local machine
git clone https://github.com/InabaKumori/Form-Data-To-Postgres.git
-
Navigate to the project folder
cd Form-Data-To-Postgres
-
Install required packages
npm install
-
Run the application
node app.js
To test the API, make a POST
request to http://localhost:30000/post/contact
with the appropriate form data.
Here is a sample cURL request:
curl --location --request POST 'http://localhost:30000/post/contact' \
--form 'name="John Doe"' \
--form 'email="john.doe@email.com"' \
--form 'message="Hello, World!"'
- POST /post/contact: Endpoint for receiving form data.
Create a .env
file in the root directory of your project and add the following:
DB_HOST=your_database_host
DB_USER=your_database_user
DB_PASSWORD=your_database_password
DB_NAME=your_database_name
Replace the placeholders with your actual PostgreSQL database information.
Here's an example SQL command to create the table:
CREATE TABLE contact_forms (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
message TEXT
);
Error responses come in the following JSON structure:
{
"error": "Error message goes here"
}
- Fork the project.
- Create your feature branch (
git checkout -b feature/YourFeature
). - Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/YourFeature
). - Open a pull request.
This project is licensed under the GNU License. See the LICENSE file for details.
- Thanks to all contributors and their valuable input.
- This project was inspired by the need for a simple, reliable way to manage client form submissions.