Lets say I have a expressjs site up and I have a 2-3 second runtime async function, how am I able to run multiple instances without returning errors and overlapping data if the functions were called at the same time.
app.set('view engine', 'ejs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use('/css', express.static(__dirname + 'public/css'));
app.use('/img', express.static(__dirname + 'public/img'));
app.use('/public', express.static('public'));
app.get('/', function(req, res) {
res.render('index');
});
app.get('/faq', function(req, res){
res.render('faq');
})
app.get('/contact', function(req, res){
res.render('contact');
})
app.get('/submitorder', function(req, res){
res.render('submitorder');
})
app.post('/order', async function(req,res){
var data = fs.readFileSync('tokens.txt', 'utf-8');
if(data.includes(req.body.token)){
var newValue = data.replace(new RegExp(req.body.token), "");
newValue.replace(/^\s*\n/gm, "");
fs.writeFileSync('tokens.txt', newValue, 'utf-8');