Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

mongo db connection

const start = async () => {
    
    if (!process.env.DB_URI) {
        throw new Error('auth DB_URI must be defined');
    }
    try {
        await mongoose.connect(process.env.DB_URI!, {
            useNewUrlParser: true,
            useUnifiedTopology: true,
            useCreateIndex: true,
        });
        console.log('Server connected to MongoDb!');
    } catch (err) {
        throw new DbConnectionError();
        console.error(err);
    }

    const PORT = process.env.SERVER_PORT;
    app.listen(PORT, () => {
        console.log(`Server is listening on ${PORT}!!!!!!!!!`);
    });
};

start();
 Run code snippetHide results
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #mongo #db #connection
ADD COMMENT
Topic
Name
3+3 =