I have 2 variables. One is assigned inside a .then
and the other assigned in a function. Later on only 1 is defined.
Code excerpt...
let user;
let station;
const app = express();
app.post("/api/user", (req, res) => {
user = req.body.user; // Breakpoint added here to confirm user set
}
// Uses serialport module. Called when data received on serial port
function serialPortListener(data) {
getStation(data) // Retrieves record from database
.then(s => {
station = s; // Breakpoint added here to confirm station set
...
}
I set breakpoints on both methods to confirm the variables are set. When I try to access them, later on, only user
is defined. I'm assuming it's something to do with the context in which station
is set?
station
is not assigned anywhere else.