This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); // importing the http module | |
const fs = require('fs'); // importing fs module although I'm not using it in this demo , but just for convenience for the next demo where I would be using it | |
const hostname = '127.0.0.1'; // Plss note that you can use Localhost instead of this address if you can't memorize it | |
const port = 80; // Any port where you would like your server to listen , but i recommed you in using port 80 as you don't have to type anything after http://localhost/ | |
const server = http.createServer((req, res) => { | |
res.statusCode = 200; // Status Code | |
res.setHeader('Content-Type', 'text/plain'); // Header of the web server | |
res.end('Hello World !! This a simple Node js Web Server '); // Simple demo with hello world but instead of it you can serve your Html file also |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
const bodyParser = require('body-parser'); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.post('/submit', (req, res) => { | |
const formData = req.body; | |
// Process formData here | |
console.log(formData); |