nodejs

 // Importing the Express module

const express = require('express');
const app = express();
const port = 3000;

// Middleware to handle JSON data (in case your form sends JSON data)
app.use(express.urlencoded({ extended: true }));

// Route to handle GET requests to the root URL
app.get('/', (req, res) => {
  res.send('Hello, this is your backend server!');
});

// Route to handle POST requests when the form is submitted
app.post('/submit', (req, res) => {
  const { name, email, message } = req.body;
  console.log('Form Data Received:', { name, email, message });
 
  // Here, you can process the data (e.g., save it to a database)

  res.send('Form submitted successfully!');
});

// Starting the server
app.listen(port, () => {
  console.log(`Server is running at http://localhost:${port}`);
});

Comments

Popular posts from this blog

Petroleum