BackEnd/Node&Nest

nodejs res.download 사용법

Fathory 2020. 1. 30. 14:55

1. router

router.get('/download', function(req,res,next){
	let filename = "tmp/file.txt";
	res.download(filename, filename_client, function(err){
    	if(err){
        	res.json({err:err});
        }else{
        	res.end();
        }
    })
}

2. JS

function download(){
	window.location.assign("/download");
}

 

반응형