My First Hackathon Journey with Coderweb

Hello everyone, today Iā€™m excited to share my inaugural experience participating in an online hackathon hosted by Devfolio called Hackofest. This marked my first foray into the world of hackathons, and I embarked on this journey solo under the team name Coderweb. With just a week to prepare, I dove headfirst into honing my skills and gearing up for the challenge ahead. This time around, I set my sights on delving into the realm of backend development, particularly focusing on crafting websites with robust databases.

I dedicated ample time to research and familiarize myself with backend development frameworks like Node.js and Express.js. Given my prior familiarity with MySQL, I took the opportunity to brush up on my database management skills. Fortunately, thereā€™s a wealth of resources available for aspiring developers, ranging from platforms like Beginner for Beginner to insightful tutorials on Free Code Campā€™s videos.

Fueled by a passion for innovation, I conceptualized a project idea: a cosmetic analyzer. Setting the foundation for my endeavour, I meticulously compiled and organized a dataset based on extensive research into the chemical ingredients commonly found in cosmetics. As the hackathon commenced, I began by crafting the front end of my project, leveraging AI assistance to streamline the process. With a solid front end in place, I seamlessly transitioned to the backend section, intertwining webpages, implementing Tesseract image recognition, and establishing robust database connectivity.

As the submission deadline loomed closer, I diligently fine-tuned my project, ensuring it met the requisite standards. Despite the intensity of the competition and the awe-inspiring projects presented by fellow participants, I remained undeterred, appreciating the ingenuity and creativity showcased by my peers. Above all, this experience served as a poignant reminder of the importance of perpetual learning and growth. With each challenge embraced and every obstacle overcome, I reaffirmed my commitment to lifelong learning and innovation.

In conclusion, while the outcome of the hackathon remains to be seen, the invaluable lessons gleaned and the personal growth attained throughout this journey are undoubtedly its greatest rewards. As I eagerly anticipate the results, I am emboldened by the knowledge that regardless of the outcome, the journey itself has equipped me with invaluable skills and insights that will undoubtedly shape my future endeavours.

Node
const express = require('express');
const multer = require('multer');
const Tesseract = require('tesseract.js');
const mysql = require('mysql');
const path = require('path');


const bodyParser = require('body-parser');
const session = require('express-session');
const bcrypt = require('bcrypt');
const http = require('http');
const socketIO = require('socket.io');
const app = express();
const server = http.createServer(app);
const io = socketIO(server);
const upload = multer({ dest: 'uploads/' });
app.set('view engine', 'ejs');


// Middleware setup
app.use(bodyParser.urlencoded({ extended: false }));
app.use(session({
    secret: 'secret_key', // Change this to a more secure value
    resave: true,
    saveUninitialized: true
}));


// MySQL connection setup
const connection = mysql.createConnection({
    host: 'localhost',
    user:  // Replace with your MySQL username
    password: // Replace with your MySQL password
    database: 'businessdb'
});


connection.connect(err => {
    if (err) {
        console.error('Error connecting to MySQL:', err);
        return;
    }
    console.log('Connected to MySQL');
});


// Tesseract.js function
function extractTextFromImage(imagePath) {
    return new Promise((resolve, reject) => {
        Tesseract.recognize(imagePath, 'eng')
            .then(({ data: { text } }) => {
                resolve(text);
            })
            .catch(error => {
                reject(error);
            });
    });
}


// Routes (excluding sensitive content)
app.get('/public', (req, res) => {
    res.sendFile(path.join(__dirname, 'public', 'index.html'));
});


// Upload route with Tesseract.js integration
app.post('/upload', upload.single('image'), (req, res) => {
    if (!req.file) {
        return res.status(400).send('No files were uploaded.');
    }
    const imagePath = req.file.path;


    extractTextFromImage(imagePath)
        .then(text => {
            // Process extracted text...
            console.log('Extracted text:', text);
            res.send('Text extracted successfully');
        })
        .catch(error => {
            console.error('Error occurred during text extraction:', error);
            res.status(500).send('Error occurred during text extraction.');
        });
});


// Listen for new connections
io.on('connection', (socket) => {
    // Handle socket events...
});


// Server initialization
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
    console.log(`Server running on port http://localhost:${PORT}`);
});




Contact Us