Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

nodejs transofrm method into promise method

import path from 'path'

async function resolveAsync(...pathSegments: string[]): Promise<string> {
	const resolve: any = await Promise.resolve(path.resolve)
	return resolve(...pathSegments)
}

;(async () => {
	// sync version
	const dirSync: string = path.resolve('index.txt')
	console.log(dirSync)

	// async version
	const asyncDir: string = await resolveAsync('index.txt')
	console.log(asyncDir)
})()
 
PREVIOUS NEXT
Tagged: #nodejs #transofrm #method #promise #method
ADD COMMENT
Topic
Name
7+6 =