Is it possible to use Node.js in NetSuite/SuiteScript? - netsuite

I am wondering if it is possible to reference node modules in SuiteScript. For example, I am aware that I can create a third party library in the file cabinet and reference the moment.js file. However, is it possible to do an npm install moment on your suitecloud project and then have access moment in that script by simply importing it as you would in Node?

Actually you cannot use Node.js inside suite script. But you can trigger scripts from Node.js. Example if you want to create a record from a json file, you can trigger node.js to pass the json to a Map/Reduce or RestLet script.

is it possible to do an npm install moment on your suitecloud project and then have access moment in that script by simply importing it as you would in Node?
Yes and no. What you could do in this case is to copy the required .js files along with the SuiteScript files when doing the deployment, having in mind that the SS files would be referencing the library using a relative path.
All of this could be programmed as a task in node (or maybe webpack), which would all execute in your machine, and then upload the results to NetSuite.

Related

How to write inside a file at specific position using nodejs?

I am building an interactive CLI project generator and I want to have a similar feature like angular CLI have.
Although I am working on to generate folders and files but I am not sure that how can I write inside a file at a specific position.
Suppose, when we generate a component using angular cli, it registers the component inside our modules file. So how can I write inside a file at specific location? Say if I want to include a require tag in node inside a file how would I do it? How would I know at what position the imports are ending and at what position do I include it?
You could create simple CLI using REPL module in Node.js
https://nodejs.org/dist/latest-v10.x/docs/api/repl.html
For creating folders/files you could use fs module
https://nodejs.org/dist/latest-v10.x/docs/api/fs.html
For running external commands (like git init), you could use child_process module (exec method)
https://nodejs.org/dist/latest-v10.x/docs/api/child_process.html#child_process_child_process_exec_command_options_callback

Use NodeJS Helper Script in Meteor

I have written a small helper module in regular NodeJS to be used with NodeJS batch scripts. I've placed this and all the batch scripts in the "private" folder inside my Meteor project.
I'd like to also use the helper module on the server-side of Meteor as well, but I don't know the best way to handle that.
This is my current project structure:
client
... client files ...
private
scripts
helpers.js
batch_script1.js
server
... server files ...
So for Meteor to include the "helpers.js" file into the server, it either has to be located in the "server" folder, or imported via a package. Creating a symlink won't work, as multiple developers will be working on this and may have the repository checked out to a different directory location (seeing as how you need an absolute path to create a symlink).
I also don't want to have to duplicate the file and maintain two copies, so what are my options for sharing a helper script between a Meteor app and a NodeJS script?
Thanks
I was able to find help on the Meteor forums: https://forums.meteor.com/t/use-nodejs-helper-script-in-meteor/11056/3

How to test NodeJs CLI javascript

I need to put some tests around a nodejs command line utilities\modules. No browser involved and I'm using a lot of the "fs" module to work the file system, so i'm not sure a browser based test mechanism would work (sandboxing).
any modules that would help here?
Check out Vorpal.js. This lets you create an interactive CLI in node, in which you can then run custom commands to test the various things you want to test.
Disclaimer: I am its author.

Ember-cli addon read configurations

I am trying to create an ember-cli addon and I want this addon to include custom command. This part I have already done by creating a lib/commands file structure and including the script that will run the command then used includedCommands in the addon index.js.
The part I am struggling with is I want the command to be able to read a configuration file within the host applications directory. How can I do this? If I could find out the host apps absolute path I suppose I could parse a file using built in node tools but how do I find this path?
If there are better ways to accomplish this task I am all ears.
In your commands run function, you can access this.project which provides details about the project.
What you want to use is this.project.root.. it's the root directory of the project.
I have managed to solve the problem. Don't know if it is the best way. So I am able to obtain the absolute process path in node just by using process.cwd() Then I can simply append a config file name to the end of the string to get my config file absolute path.
If there are any ember-cli specific ways that I should be doing this then please let me know.

Deploy a node.js application (windows)

for a customer of mine i'm developing a node.js app.
I want to give him a simple setup program that handle the installation of node and relative modules in automatic without having to access the web.
Which is the best and efficient way to do that?
Thanks in advance
Just give him the node.js installer und zip your app (with node_modules directory). He just has to install node.js and extract the zip file. You could write a .bat file which starts the app. That should be easy enough.

Resources