# How to source a js script file using collections sdk

**URL:** <https://community.postman.com/t/how-to-source-a-js-script-file-using-collections-sdk/4854>\
**Category:** Help Hub\
**Tags:** scripts, sdk, javascript\
**Created:** [April 4, 2019, 3:22pm UTC](https://community.postman.com/t/how-to-source-a-js-script-file-using-collections-sdk/4854 "2019-04-04T15:22:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonsegal](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/leonsegal/32/1511_2.png) [@leonsegal](https://community.postman.com/u/leonsegal)\
**Post date:** [April 4, 2019, 3:22pm UTC](https://community.postman.com/t/how-to-source-a-js-script-file-using-collections-sdk/4854/1 "2019-04-04T15:22:35Z")

</div>

Hi

I am trying to use a separate script file using your collection sdk.

In the docs, it says you can reference the file location using `src` and point it relative to the script.

Every variation I have tried has failed so far though:

**’script.js’**

**’/script.js’**

**’./script.js’**

If I use `exec` , it works fine though i.e when I open up postman and edit the folder, I can see my code where I want it (in the folder).

MY COLLECTION.JS:

**// variables**

**var fs = require("fs"), // for IO**

**Collection = require(‘postman-collection’).Collection,**

**Item = require(‘postman-collection’).Item,**

**ItemGroup = require(‘postman-collection’).ItemGroup,**

**Script = require(‘postman-collection’).Script,**

**myCollection,**

**myScript;**

**// create the collection**

**myCollection = new Collection({**

**"name": "collection",**

**"id": "collection",**

**});**

**// add the folder**

**myCollection.items.add(new ItemGroup({**

**"id": "folder",**

**"name": "folder"**

**}));**

**// add requests to the search folder**

**myCollection.items.one("folder").items.add(new Item({**

**"name": "request",**

**"id": "request",**

**"request": {**

**"url": "[https://postman-echo.com/](https://postman-echo.com/)",**

**"method": "GET"**

**}**

**}));**

**// add scripts to the search folder**

**myScript = new Script();**

**myScript.update({**

**// exec: 'console.log(“inline”)'**

**src: './script.js’**

**});**

**myCollection.items.one("folder").events.add({**

**listen: "test",**

**script: myScript**

**});**

**// export the collection**

**fs.writeFileSync("collection.postman\_collection.json", JSON.stringify(myCollection, null, 2));**

MY SCRIPT.JS (IN SAME FOLDER AS COLLECTION.JS):

**console.log(‘from file’);**

So my question basically is: how can I point to a separate file to bring in my js code?

I am wondering if I need to use `fs` somehow to read the file in?

Any help would be greatly appreciated.

Thanks

Leon

---

<div class="post-metadata">

**Author:** ![MishaBindra](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@MishaBindra](https://community.postman.com/u/MishaBindra)\
**Post date:** [July 7, 2020, 3:28am UTC](https://community.postman.com/t/how-to-source-a-js-script-file-using-collections-sdk/4854/2 "2020-07-07T03:28:48Z")

</div>

Hi , I am encountering a similar issue.Did anyone find a solution to this problem?
