Sublime Text says "No Build System" on Ubuntu/Linux - javascript

Recently i switched to Ubuntu/Linux and searched for some good text editor and i found Sublime Text, i'm very beginner at coding and i was using Notepad++ in windows.
After i downloaded sublime text, i tried to write some codes in javascript to see if it works but it said "No Build System" and when i looked for it, i didn't find any guide for linux... in Notepad++ all i have to do was click run and ta da, the output screen was there.
I don't know much about linux or sublime text, my exact question is how can i run and see my codes in the output screen, currently i'm working on Javascript and i have no idea what a "Build System" is, i just want to type some basic code in sublime text and see the result on the screen, so if you help me i'll be much appreciated.
Here's an image the problem:

In order to explain your problem it's first important to realize that although the feature is called build, it applies just as much to running an interpreted program as it does to actually building anything; think of it less as a "build" tool and more as a "run some external program to do something" tool instead.
With that said, Sublime comes pre-installed with a few different build systems for various languages, but JavaScript isn't one of them. Possibly this is because it's generally unclear whether a particular JavaScript file is meant to be used in a browser, or executed via something like node, but that's just a guess.
In your case, the text No build system is literally telling you that you have told Sublime to automatically select an appropriate build system for the type of file that you're editing, but that it didn't find one and so there's nothing that it can do.
The solution to the problem would be to either install a third party package that includes a JavaScript build system (see Package Control) or create one yourself.
A good rule of thumb for Sublime is that if there is a command you can execute from a command prompt that will do what you want, and you don't need to interact with that command (i.e. it doesn't need to ask you questions before or while it does something), you can set up Sublime to run that command for you.
One tool you can use to execute JavaScript is NodeJS, which provides a command named node that can execute JavaScript files if you install it:
tmartin:dart:~> cat sample.js
console.log("Hello, world!")
tmartin:dart:~> node sample.js
Hello, world!
Since this is a command that we can execute from a terminal to do what we want, and it doesn't require us to interact with it to tell it how to do anything, we can set up a build system to use it.
As an example of how to do that, select Tools > Build System > New Build System... from the menu, and then replace the contents of the file with the following code, then save it in the location that Sublime will default to as something like JavaScript.sublime-build:
{
"shell_cmd": "node \"${file}\"",
"selector": "source.js"
}
This simply says that when executing this build, Sublime should use the command node and provide it the name of the file that you're currently editing, and that this build system applies to source files of type js (JavaScript).
With that in place, if you select Tools > Build System > Automatic or Tools > Build System > JavaScript (the name in the menu reflects the name you used for the file), you should be able to use Ctrl+B to execute your program:
Note: This is an older image and uses cmd instead of shell_cmd; both examples will work the same way but shell_cmd is the recommended way to go unless you have a compelling reason not to.
You can check out the official documentation on build systems for more information on the options available to you in a build system.
Important notes:
If you get an error like command not found or something similar, it means that you either entered the command incorrectly, that program is not installed, or you need to tell your computer (and thus Sublime) where to find it by modifying your PATH; how you do that is system specific.
Make sure you save a new file manually at least once before you try to run it; before you do the file isn't on disk yet and can't be executed, which can cause strange errors to occur. It can be a good idea to make sure that Tools > Save all on build is checked to ensure your files on disk are always up to date when you build, but this won't save a new file that doesn't have a name yet.
I said this twice, but it bears repeating; if you need to interact with a command in any way, this won't work for you (without changes on your end). This includes if you try to execute a script that wants you to interact with it (e.g. it asks you your name and then prints it and such like). In such a case your program will seem to hang forever because it's waiting for input that you can't provide.

Related

How to get readline-sync working in JavaScript in VisualStudioCode?

I would like to allow a JavaScript program running in VisualStudioCode to use readline-sync, but when I try to use the
const input = require('readline-sync');
line that works in environments like Replit after causing that module to be added, I get an error message about not having the appropriate module. In trying to find an answer to this question, I have gotten the impression that modifying a "package.json" file is involved. However, I'm not sure exactly where this file is supposed to be and believe that I may not have one for my current project yet. When I use VSC's Command Palette to enter the
JavaScript: Go to Project Configuration
command, I get a popup in the lower-right corner that says
"Please open a folder in VS Code to use a TypeScript or JavaScript project
Source: TypeScript and JavaScript Language Features (Extension)"
I believe that the problem may have something to do with the fact that I have previously mainly used VSC for standalone code pages that interacted only with the console or with languages other than JavaScript and am not really familiar with how to set up a project that requires multiple files to work in conjunction in the VSC environment.

How to compile Javascript console application locally?

I am a beginner in Javascript, I decided to practice Javascript by problem solving using it, I found an online judge that accepts Javascript V8 4.8.0 code.
So, I searched online to get that version of Javascript V8 on my machine, but I couldn't find any easy way, All the pages were explaining how to build it, and it seems to be a process that I don't need to go through.
Is there an easy way to compile and run command line apps written in Javascript on my machine?
Note: I don't want to use node.js because I tried using it's I/O and
as a beginner I think it is complex in some way.
Update: I found that package manager pbox.me which provides a version of V8 JavaScript Engine and I managed to install it.
Yet another problem appeared: whenever I try to run a js file writing d8 myfile.js in command line nothing happens as if it is an empty program, knowing that I tryied to d8.exe file and it is working, and I made sure the PATH is inserted in the environment variables.
What am I doing wrong?
The easiest way to get started with JavaScript is probably to use it in a browser. You can type simple things directly into the browser's JavaScript console (check the menu); or you can embed your code in a simple HTML document.
If you want, you can even pretty easily implement the readline()/print() functions, so you can pretend to be doing stdin/stdout based I/O: just read from an array of strings, and send output to console.log (or create DOM nodes if you want to be fancy and/or learn how to generate dynamic website content by hand).
Side note: V8 4.8 is severely outdated, don't use it to execute code you haven't written yourself.

Need help p5.js and Atom Text Editor

Well I recently started off with atom and p5.js well I am very new to JavaScript. Here comes my problem : When I try to run the file it shows me "sketch.js is not a .py file, exit" . I checked the the selection is set to JavaScript but can't figure out what is wrong.. Please Help !
Well the "sketch.js" is the default one which comes with "p5.js" and yes I have installed "node.js" so no issues with that and the problem comes when I edit the "Sketch.js" template and try to run it , it shows saving and after that it says "sketch.js is not a .py file, exit"
You need to isolate your problem. Is the problem in the Atom editor, or is it with P5.js?
Try running your sketch as a standalone .html file that you create with a basic text editor (like JEdit or Notepad, not with Atom). Can you get that working by itself?
Then try running a more basic JavaScript application in Atom. Try simply printing something to the console. If you're still getting the error, then you know it has nothing to do with P5.js.
Isolating your problem like this will help you refine your Google searches, and it will make it easier for people to help you.
Note that P5.js does not require node.js, which runs on a server. It requires regular client-side JavaScript.
I'll also just note that if you're having trouble with stuff like this, it's a good idea to stick with a basic text editor and write and run your code by hand for a while. Code editors hide a lot from you, which can be nice, but not if you're still learning the fundamentals.
You are likely using an editor like Genie or something which runs python programs by default. Have you installed node.js? If not install it and then browse to the directory using command prompt. Then run "C:\Program Files\nodejs\node.exe" file.js

Use JavaScript Node command line tool in Chrome

Hey I have an app written in js being accessed by $ node script.js
I want to visualize the output of it and thought it'd be a good idea to just "wrap" a HTML page around it. For example in the output in the terminal there are 2 values gradually increasing and I'd like to process both of them in a way that they could represent 2 bars that, according to the 2 values, rise accordingly.
However, I've never done anything in JS and I don't really know the best way to do it.
I found http://iceddev.com/blog/node-js-in-chrome/ to host a local server to run my .js on this but not even the console.log or any errors in the code in the index.js (which is basically opening the server and contains the content you want to see when navigating to it in Chrome) show up in the Chrome console so I am wondering if there is something else I can do here.
To run your script in the browser I recommended you to look this package http://browserify.org/ it compile your js script into browser compatible js

Is there any Mac text editor with tail or watch files change feature?

Ideally I wanted to use this in TextMate but I didn't find any feature besides the Show Web Preview which is nice for the fact I can set the interval to update the page, but definitely doesn't work for watching any file and also apply syntax highlighting or any format.
One neat example of what I wanted to achieve is to simulate exactly the same behavior as CoffeScript Try Now feature where you can type in one side and see what the file would look like in javascript.
So ideally I would open my .coffee file and then run coffee --watch on terminal which will track any file change for that specific file, so I could just pop another window inside my text editor which will just keep updating the coffeescript .js generated file.
like this, where the window on the left shows the current file and the window on the right shows the file being watched with specific interval.
I am not sure if I was clear enought, if not, please just let me know..
but basically I just want to see in real time what happens to my files after run a specific script but with syntax highlighting and anything else possible.
I am just testing this kaleidoscope app, it is really nice the way the visualization works, no editing is possible neither syntax highlighting features though but it is really good, so it makes me think that something like this would be really nice:
cheers
Emacs can do both of these things (and you're probably better off running it as a Cocoa app).
ediff works similarly to Kaleidoscope (minus the diagonal lines connecting the two revisions) and does let you edit the files without disturbing the diff process. By default you get the versions above one another but you can press | to toggle to side-by-side and m to expand to the full screen width (unfortunately this doesn't work properly with multiple monitors, at least in the version of Emacs I'm using.)
To tail/auto-revert things, there's auto-revert-mode and auto-revert-tail-mode built into Emacs.
emacswiki.org is pretty good if you're trying to figure out how to do something in Emacs, as is (duh) Stack Overflow. Mastering Emacs is a relatively new blog which has some great articles. There's also M-x all-things-emacs which links to some useful screencasts.
You can open the log file in OSX's Console log viewer utility that is used to monitor system logs. Simple as that. It will not show you diff's but it does emulate the tail -f functionality.

Categories

Resources