I have create a class in nodejs
class ApnService {
sendNotification(deviceType, deviceToken, msg, type, id) {
try {
const note = await apnProvider.send(note, deviceToken)
console.log(note)
} catch (err) {
console.log(err)
}
}
}
export default ApnService
What I need to do is to convert above function to async
. But when I use below syntax It throws me error
SyntaxError: src/services/apn.js: Unexpected token (43:19)
41 | }
42 |
> 43 | sendNotification = async(deviceType, deviceToken, msg, type, id) => {
|
^
Below is the syntax
class ApnService {
sendNotification = async(deviceType, deviceToken, msg, type, id) => {
try {
const note = await apnProvider.send(note, deviceToken)
console.log(note)
} catch (err) {
console.log(err)
}
}
}
export default ApnService
You can simply add async before function name to declare that function as async,
class ApnService {
async sendNotification(deviceType, deviceToken, msg, type, id) {
try {
const note = await apnProvider.send(note, deviceToken)
console.log(note)
} catch (err) {
console.log(err)
}
}
}
export default ApnService