How to get string value from Promise value ? #6832
Answered
by
vekunz
magic-thomas
asked this question in
Q&A
-
I want to return string variable from set_file function, but it return 'Promise' type. how can I get string from return value ? // +server.js
export async function POST({ request }) {
let file_name = set_file();
console.log(file_name)
}
async function set_file() {
const date = new Date();
var ms = date.getTime();
return 'static/' + ms + '.png'
} Promise { 'static/1663245525814.png' } |
Beta Was this translation helpful? Give feedback.
Answered by
vekunz
Sep 15, 2022
Replies: 1 comment 1 reply
-
Promises are a basic JavaScript thing, that needs to be awaited: // +server.js
export async function POST({ request }) {
let file_name = await set_file();
console.log(file_name)
}
async function set_file() {
const date = new Date();
var ms = date.getTime();
return 'static/' + ms + '.png'
} But since you do not do any async stuff in the |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
magic-thomas
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Promises are a basic JavaScript thing, that needs to be awaited:
But since you do not do any async stuff in the
set_file
function, you can just omit theasync
from the function declaration.