Serverless-offline custom plugin define env variables

I want to boot a memory mongodb for my local development with serverless

This is the plugin I did

const { MongoMemoryServer } = require('mongodb-memory-server')

class MongoMemoryServerPlugin {


        this.hooks = {
            'before:offline:start:init': () => this.init(),
            'before:offline:start:end': () => this.end(),


    async init() {
        console.log('Starting Mongodb Memroy Server');
        this.mongod = await MongoMemoryServer.create();
        process.env.MONGODB_URI = this.mongod.getUri();

    async end() {
        console.log('Stopping Mongodb Memroy Server');
        if(this.mongod) this.mongod.stop()

module.exports = MongoMemoryServerPlugin

And in my serverless.yml I have

  - serverless-offline
  - ./plugin/mongodbMemoryServer.js

I have the log when starting and when ending but process.env.MONGODB_URI is not accessible from the serverless code

const mongodb = require("mongodb");

let cachedDb = null;

module.exports.connect = async function connect() {
    if (cachedDb) return cachedDb;

    if (!process.env.MONGODB_URI) throw new Error('Environment variable MONGODB_URI not defined')

    const client = await mongodb.MongoClient.connect(process.env.MONGODB_URI);

    const db = client.db("db");

    cachedDb = db;
    return db;

when trying to connect, I have Environment variable MONGODB_URI not defined