User: Task: "Create Regiser Api for User"
    Description: "Generate a Node.js Regiser Api with with given dependenceis"
    Requirements:
    - Database: mongoose
    - Authentication: None specified
    - Output needed: Return only the function code as specified in dependencies
    - Dependencies: Create Register api function as exported function it's self. function mode :-  exports.functionname = async () =>{...}, 
Accept two parmas request and response, 
Accept two creidentional from User one email and passowrd, 
User cridentional should validated by joi, 
Api should build inder try catch method for error handeling., 
For hashing use bacrypt lirbary, 
Data should be saved in User database ., 
import the User Schema from this folder ../models/User.js as User , 
While registering you have to store all field in the refrencen User schema below given, 
Response should send back in Json formate with 'status' code of 200
    - Previous Code 
const User = require('./models/User'); // assuming you have a User model defined using mongoose
const client = redis.createClient(); // create a redis client

exports.loginApi = async (req, res) => {
    try {
        // Validate user input using Joi
        const schema = Joi.object({
            email: Joi.string().email().required(),
            password: Joi.string().min(6).required()
        });

        const { error } = schema.validate(req.body);
        if (error) {
            return res.status(400).json({ status: 'error', message: error.details[0].message });
        }

        const { email, password } = req.body;

        // Find user in the database
        const user = await User.findOne({ email });
        if (!user) {
            return res.status(400).json({ status: 'error', message: 'Invalid email or password' });
        }

        // Compare the password with the stored hash
        const validPassword = await bcrypt.compare(password, user.password);
        if (!validPassword) {
            return res.status(400).json({ status: 'error', message: 'Invalid email or password' });
        }

        // Store logged users in Redis with key logUser
        client.set('logUser', email, redis.print);

        // Respond with success status
        res.status(200).json({ status: 'success', message: 'Login successful' });
    } catch (err) {
        console.error(err);
        res.status(500).json({ status: 'error', message: 'Internal server error' });
    }
};

exports.registerApi = async (req, res) => {
    try {
        // Validate user input using Joi
        const schema = Joi.object({
            email: Joi.string().email().required(),
            password: Joi.string().min(6).required()
        });

        const { error } = schema.validate(req.body);
        if (error) {
            return res.status(400).json({ status: 'error', message: error.details[0].message });
        }

        const { email, password } = req.body;

        // Hash the password using bcrypt
        const salt = await bcrypt.genSalt(10);
        const hashedPassword = await bcrypt.hash(password, salt);

        // Creating a new user
        const newUser = new User({
            email: email,
            password: hashedPassword
        });

        // Save the user to the database
        await newUser.save();

        // Respond with success status
        res.status(200).json({ status: 'success', message: 'User registered successfully' });
    } catch (err) {
        console.error(err);
        res.status(500).json({ status: 'error', message: 'Internal server error' });
    }
};

    - Supporting data 
    - Updating File undefined
    
    Please generate the code for this task, following the instructions and including comments for clarity.
    While creating router for specifict file your have to read supporing file data and create for that 

    **Output Formats**: 

Return dependencies like this `const bcrypt = require('bcrypt');`  in this formate
```dependencies
const bcrypt = require('bcrypt');
```

Ensure this format is consistently followed in responses.
    
User: 


    
Assistant: