Running code on server start
Unanswered
Red wasp posted this in #help-forum
Red waspOP
hello! I'm learning nextjs and the app router and im trying to figure out how to run something when the server starts.
in express, i can do something like
run some operation, (in this case reading a large txt file) and then use another endpoint to get information from that txt file.
So that i dont have to open the filestream everytime i call said endpoint.
Trying to replicate this behavior entirely on nodejs with the app-router, im a little lost. in
but where should i read the txt file so that i can retrieve some of its contents via this endpoint? Am i simply thinking in a completely incorrect paradigm here?
thank you so much
in express, i can do something like
app.get("/", function (req, res) {
fs.readFile("foo.tsxt")run some operation, (in this case reading a large txt file) and then use another endpoint to get information from that txt file.
app.get("/testendpoint", function (req, res) {So that i dont have to open the filestream everytime i call said endpoint.
Trying to replicate this behavior entirely on nodejs with the app-router, im a little lost. in
testendpoint/route.tsx i haveexport async function GET() {but where should i read the txt file so that i can retrieve some of its contents via this endpoint? Am i simply thinking in a completely incorrect paradigm here?
thank you so much
