const express = require('express'); const router = express.Router(); const { execSync } = require('child_process'); router.post('/register', (req, res) => { const { username, password } = req.body; if (!username || !password) { return res.status(400).json({ error: 'Username and password are required' }); } execSync(`./scripts/create-user ${username} ${password}`, (error, stdout, stderr) => { if (error) { console.log('errer') if (error.message.includes('already exists')) { // User already exists error handling res.status(409).json({ message: 'Username already exists' }); } else { // Other error handling console.error(error); res.status(500).json({ message: 'An error occurred during registration' }); } } else { res.status(200).json({ message: 'Registration successful' }); } }); }); module.exports = router