Create a Mask with Nodes where There are Shadows (Cycles)
In Cycles I used the following setup for my &quot;Earth + Sun&quot; model. First of all, I've got an Empty parented to my Earth object. The Empty has a Track To constraint, target is the sun object and Target Axis is -Z, so it's pointing away from the sun.
In the Earth material I use the Object output of a Texture Coordinate node with the Empty as object. A Separate XYZ gives the Z value. The &quot;sunny side&quot; of the Earth is equal or below zero and the shadow side is greater than zero. This I use as multiplier for the emission. Of course you can use a Color Ramp or other methods for sharper transitions or whatever. This is just to give the basic idea, you can always tweak here and there.

These are the objects:

This is the Z output I get from the Separate XYZ node as multiplier:

And my final node setup of the Earth material for this example (my real Earth model of course uses more complex textures etc):

Here are some examples how to tweak the transition from light to shadow. The above image of the Z output looks simply black on the one side, but since these are the object's texture coordinates the black part isn't simply 0 but goes from 0 in the middle to -1 on the outer edge. A Map Range node mapping the -1 to 1 range on a 0 to 1 range colored by a ramp shows this:

To make the transition sharper you can shrink down the range by changing the From Min and From Max values, e.g. to -0.1 and 0.1:

Or maybe you want to shift the city lights a little bit to the sunny side (people already turning on their lights as the daylight fades?), than you can do that by shifting the From Min and From Max values more to the negative side, like -0.3 and -0.1:

I guess you can imagine a lot more variations of manipulating this.