Getting started
Core concepts
Build and deploy
Advanced
Best practices
Appendix
Reference
- @sveltejs/kit
- @sveltejs/kit/hooks
- @sveltejs/kit/node/polyfills
- @sveltejs/kit/node
- @sveltejs/kit/vite
- $app/environment
- $app/forms
- $app/navigation
- $app/paths
- $app/server
- $app/state
- $app/stores
- $env/dynamic/private
- $env/dynamic/public
- $env/static/private
- $env/static/public
- $lib
- $service-worker
- Configuration
- Command Line Interface
- Types
SvelteKitReference
$app/server
import{functiongetRequestEvent():RequestEvent<Partial<Record<string,string>>,string|null>
Returns the currentRequestEvent
. Can be used insidehandle
,load
and actions (and functions called by them).
In environments withoutAsyncLocalStorage
, this must be called synchronously (i.e. not after anawait
).
@since2.20.0getRequestEvent,functionread(asset:string):Response
Read the contents of an imported asset from the filesystem
@examplejs import { read } from '$app/server'; import somefile from './somefile.txt'; const asset = read(somefile); const text = await asset.text();
@since2.4.0read}from'$app/server';
getRequestEvent
Available since 2.20.0
Returns the currentRequestEvent
. Can be used insidehandle
,load
and actions (and functions called by them).
In environments withoutAsyncLocalStorage
, this must be called synchronously (i.e. not after anawait
).
functiongetRequestEvent():RequestEvent<Partial<Record<string,string>>,string|null>;
read
Available since 2.4.0
Read the contents of an imported asset from the filesystem
import{functionread(asset:string):Response
Read the contents of an imported asset from the filesystem
@examplejs import { read } from '$app/server'; import somefile from './somefile.txt'; const asset = read(somefile); const text = await asset.text();
@since2.4.0read}from'$app/server';importconstsomefile:string
somefilefrom'./somefile.txt';constconstasset:Response
asset=functionread(asset:string):Response
Read the contents of an imported asset from the filesystem
@examplejs import { read } from '$app/server'; import somefile from './somefile.txt'; const asset = read(somefile); const text = await asset.text();
@since2.4.0read(constsomefile:string
somefile);constconsttext:string
text=awaitconstasset:Response
asset.Body.text():Promise<string>
text();
functionread(asset:string):Response;
previousnext