-1

I tried to extend the Global object in NodeJS like global.spotConfig. I have been searching for answers but have no one fit

Please help me, my code is here

Note: Restart server on SERVER CONTROL PANEL if it not run

user2143218
  • 41
  • 1
  • 8

1 Answers1

1

See https://stackoverflow.com/a/35074833/1937643.

In your case, you want:

var http = require("http");

declare module NodeJS {
    interface Global {
        spotConfig: string
    }
}

//create a server object:
http
    .createServer(function (req, res) {
        // assign a new value to the global property
        global.spotConfig = "anything";
        console.log(global.spotConfig);
        // error TS2339: Property 'config' does not exist on type 'Global'.
        res.write("Hello World!"); //write a response to the client
        res.end(); //end the response
    })
    .listen(8080); //the server object listens on port 8080

jmellman
  • 456
  • 3
  • 5