Format a drive in node.js - javascript

I'm working on a project in node.js and I'm stuck at this. I need to convert an external device ( a usb stick etc.) into an "exFAT" partition if it's not an exFAT . I used an npm package called "drivelist-scanner" to get the list of usb devices connected and also their mountpoints. Now the only thing left to do is to convert them into exFAT and I don't know how to do it. I came across an npm package called "gpt" which said it can format drives but the documentation is not so clear. Here's a link to the github repository for gpt : Github link
Any ideas on how to accomplish this? I'm even willing to launch a script based on the operating system to do the job, but I'm not sure on how to do this too. Any help is appreciated. Thanks.

Actually you can not directly format a drive with programming languages. You will need to invoke a operating system specific program to do the actual work for you.
Create a bash script
You can use this info for do that.
https://superuser.com/questions/274687/how-do-i-format-a-usb-drive-on-a-pc-that-was-formatted-on-a-mac
Run a bash script with node.js
You can use exec command for run a bash script with node.js
Run shell script with node.js (childProcess)

Related

Any way to generate documentation of a website project in a restricted environment?

Following the title, I have am unable to execute cmdlets, exe, shellscripts, vb. All that I am able open is git bash, but again, I have no admin rights. Are there any ways of accomplishing this? 1 idea i had was to create a local website that does this for us in the form where we upload a zip file to the website then it does its stuff then repacks it and sends it back to us via a local zip file download?
EDIT:
I am trying to document out a front end site coded in react. Only thing that is able to run anything within itself is Git Bash. No execution of .exe's or cmdlets withing Git Bash works though...
Well, apparently if u have git bash in ur restricted laptop and have the ability to push ur commit to git hub, it seems that using EDoc node module does the job.
Instead of saving globally (which won't work) do a npm install -save esdoc.
Then instead of running esdoc -c [json file], use ./node_modules/esdoc/out/src/esdoccli.js -c [json file]
Worked beautifully for me. Hope this helps anyone who faces a similar situation as me. Feel free to add additional methods to generate documentation.

How can I create a Javascript application to run in the Linux terminal?

I want to create a Javascript (using Electron) app, but I want this app to be run and executed with terminal commands, like how you run git, is there a way to accomplish this?
I know that python and ruby are better languages for this purpose but I have a reason to use electron.
For non-GUI applications, you can just use node.js directly. If you want to make a TUI, you can use node.js + a module like blessed (and possibly blessed-contrib).
Electron is basically Chromium browser with tabs and all that stuff stripped out, plus a pile of tools to work with the user's desktop environment added in. It lets you use add HTML and CSS to a Node.JS application to create a GUI.
If all you need is a terminal command, Electron is completely unnecessary.
Here's a little pile of links to help you get started creating your command line app:
Writing command line applications in Node (Free Code Camp)
Scripting with Node (Atlassian)
Node.js with Commander npm module would work very well for your requirement.

Installing Javascript client library via npm

I am very new to Node.js (which I'm assuming this is; I'm so new that I'm not really understanding what's going on here). I'm working with a client library for a system called RJ Metrics. I'm basically tying their API in with a Volusion API in order to import data into their system from the Volusion site. The code for that all makes sense but I'm not understanding how to install it and use it.
Their documentation is here:
And I'm needing to use the Javascript library because I'm working with Volusion which is on a Windows server and there is no ASP/C# option here. It says The RJMetrics Javascript client library is available via npm: and then terminal code. After research, it appeared that this uses Node.js so I installed that on my computer and ran the npm install rjmetrics in the Terminal which succeeded. I was assuming though that I must have to log into their server and run the code in order to get it to work.
Does this require me to SSH into the server? Am I way off base and is there a way I can just include some JS files in my page? I looked at their GitHub too and all of the main files use the require() function in them which I'm gathering is a Node.js function?
Apologies if I'm way off, I'm into this up to my neck and just trying to sort it all out now.
This part of the documentation (to which you refferred) is just plain ol' javascript. though NPM is the node package manager. So if you want, it looks like you can just run this .js script in a web browser like any other.
var rjmetrics = require("rjmetrics");
client = rjmetrics.Client(api_key, client_id);
# do stuff with client
If you wanted to do it in Node, you would create a .js file on your machine with their API code inside of it doing whatever you want. Then in terminal you run the script by going "node myfile.js". A local webserver setup is all you need to create and test this.

Why do frameworks and git hub ask you to use Terminal?

I'm a newbie and that's ok.
But when I use tutorials, they always tell me to go straight to my terminal and install documents from there in which I have no clue what the next step is and no idea why I have to do it. Is it essential that I install frameworks through terminal or can I just work without it?
ex. http://net.tutsplus.com/tutorials/javascript-ajax/real-time-messaging-for-meteor-with-meteor-streams/
"Let’s create a very simple, browser console based chat application with Meteor Streams. We’ll first create a new Meteor application:"
meteor create hello-stream
I understand this is may not be very challenging, but I don't have a clear answer when I try and simply google it. Anything would help, thanks a lot!
Being a newbie is ok.
The terminal is the go to because writing programs, tools, and scripts with a couple lines of bash or python is, well, a couple of lines versus an entire gui and all the lines of code to go with it.
meteor create hello-stream
That's telling you to run the program called meteor with the supplied arguments (create hello-stream).
If you haven't installed meteor, do that next. From their website, open your terminal and type/paste:
curl https://install.meteor.com | sh
That downloads a file from the URL and pipes (|) it to the sh command. The file it downloads is a shell script that takes care of setup/installation. Now go back and try the meteor command again.
More reading
You might try and find a terminal tutorial. This is the first one I found:
http://www.ee.surrey.ac.uk/Teaching/Unix/
Answer from someone who only recently (as in: within the last year) got into using the Terminal more and more frequently:
It's generally a good idea to get used to using the Terminal for code-related things as you can pretty much use it platform-independently (meaning you can use the same commands on Mac, Linux, Windows,...) and because it makes you understand better what you're actually doing.
Once you've got the hang of it, it can make navigating your system as well as making changes to it easier. Hidden files, for example (like .gitignore files, or files in your .ssh directory, or your .bash_profile), can be viewed, opened and edited easily from the Terminal whereas you have to take multiple, complicated steps (or install other software) to view them from your Finder.
With the help of package managers (like Homebrew), which are also operated from the Terminal, you can also install software that isn't otherwise available for Mac.

How to run JavaScript using jsc on OS X?

I got this when I was trying to find some way to run my JavaScript programs through terminal. The run and load command mentioned can execute external JavaScript files. Help me how to do this. I am trying to run JavaScript programs which are store locally on my system.
EDIT: I am trying to solve Project Euler Q10 in JavaScript. So this is the program that I want to run in NodeJs or JSC. I need help in running the JavaScript files in Node and JSC.
Any example will be really helpful.
Thank You all.
Complements of this post, JSC lives at
/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc
and is not in the shell PATH by default. You can fix that with
ln -s /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc /usr/local/bin
jsc takes filenames as arguments. You could run a file named demo.js with
jsc demo.js
Note that you'll have to use debug() instead of the conventional console.log() in your script to see any output.
NOTE for MacOS Catalina (10.15.x) users
jsc now lives on a new path:
/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Helpers/jsc
Make that adjustment to #hurrymaplelad's instructions and you'll be good to go.
You're not very clear on what sort of programs these scripts are. Do they do local tasks (e.g. interact with the local file system)? Or are they web scripts that are supposed to interact with (HT|X)ML documents?
If your usage scenario is the former, I recommend using node.js. It is under heavy development, but it is already very usable. For my first project with Node I wrote an XMPP chat bot, completely in JavaScript.
Edit:
I seem to have overlooked "using jsc" in the question and answered "How to run JavaScript on OS X?" instead. Still, I think Node is a better alternative if the author is looking to use JavaScript in place of something like Python or Perl.
For future reference: I made a GitHub gist with updated info on using JSC, is available here.

Categories