Skip to content

Instantly share code, notes, and snippets.

View BlazeInferno64's full-sized avatar
💻
Another day of programming

BlazeInferno64 BlazeInferno64

💻
Another day of programming
View GitHub Profile
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);
@BlazeInferno64
BlazeInferno64 / server.js
Last active May 30, 2023 16:18
Node js web server to serve html file
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