Skip to content
Advertisement

Having trouble writing form input to a seperate file in Javascript, Node.js, React.js, Next.js

I have been having a tough time writing form input to a seperate file in Javascript. I posted a repo with a demo I set up to show the problem I have been having! Feel free to take a look. https://github.com/projectmikey/projectmikey-cant-write-to-api-dir-stackoverflow

The app works fine locally from both “next dev” and “next start” when I end up at a http://localhost:3000 url.

My api at pages/api/demos/index.js responds with the body from the form’s textarea at the pages/new page and writes it as a new file at /api/newfiles/file (which becomes essentially a script file that doesnt have an extension.) This is perfect! however, I cant seem to get the file written to the /api/newfiles folder (or any other folder for that matter with fs.writeFileSync) when I am deployed live to Vercel.

I was also hoping to use shell-js to fire off a shell script (script.sh) So with this not working I have really been banging my head around trying to figure it out!

I am not an expert by any means at debugging the console log, but if I had to guess i would say it looks like there is http 400 error that is causing the problem while deployed with Vercel.

here are the key files

pages/api/demos/index.js

JavaScript

pages/api/demos/[id].js

JavaScript

pages/new

JavaScript

components/Form.js

JavaScript

script.sh

JavaScript

and here is the repo posted again https://github.com/projectmikey/projectmikey-cant-write-to-api-dir-stackoverflow

thanks in advances for any help y’all…

Advertisement

Answer

I don’t think that you can write on vercels servers

Advertisement