Calling api from script

I am using node js.
when I use same code with service script it works but not with pre/post script