简体   繁体   中英

How to start javascript project in Atom? Or any other IDE?

I am new in Atom and javascript.

I did download Atom an successfully launch him. But I not have any knowledge how start to work in it?

That what I see and try type in window:

在此处输入图片说明

It is no similar on code and I have not see a "run" or any other buttons for launch that code.

How to code and start javascript project in Atom or any other IDE?

There are a few things that I feel like I need to clarify! Javascript is a language made for the web so it generally works with HTML and CSS that is why most tutorials include HTML and CSS with the Javascript. Thus, unlike Java, Python, VB.NET there isn't a button to click and JS code runs, you have to include it into an HTML file like how @user3538203 showed.

Now I will add a few steps to start a JS program.

  1. Open Atom
  2. Open Folder in Atom (This Folder is your project folder ) by clicking on file --> Open Folder.
  3. On the left side of the screen, you will see your folder name at the top
  4. Right click on it and click on new file
  5. Name this file index.html
  6. Insert the code in @user3538203 post into your index.html file
  7. Right Click on the project folder again and make a new file called myScript.js
  8. Type your Javascript code here (ie. console.log("test"); )
  9. Go to the project folder and open index.html in the browser
  10. Press F12 and go to the Console Tab
  11. You will see the result of console.log("test") and atom will act like an IDE

Note: There are ways to make JS work in the console or as an application but these will require more knowledge about JS and you will need to install NodeJS or some special package as @user3538203 showed.

I am not sure if you can do that in Atom by default. I always just use the command line for JS with Atom/Aptana etc. if i'm using grunt, gulp, npm etc.

In order to do that you have 2 options:

  • Create an HTML page and include the Javascript into it

 <!DOCTYPE html> <html> <body> <h2>External JavaScript</h2> <p id="demo">A Paragraph.</p> <button type="button" onclick="myFunction()">Try it</button> <p>(myFunction is stored in an external file called "myScript.js")</p> <script src="myScript.js"></script> </body> </html> 

And then open the HTML file using Safari/Chrome/Firefox

  • You could also run the script from within Atom. You will have to install a Package called "script". Here is the steps in Mac OSX it will be probably similar in windows.
    1. In Mac, from Top menu. Atom -> Preference -> Install.
    2. Search for "Script" package you will find it has more than 1 Million downloads. After download you can run your script by clicking cmd +i

The solution

  1. Open Atom
  2. Make a new file
  3. Save it
  4. When you save it, you will get a prompt to rename the file from untitled
  5. Keep the title as filename.js
  6. Save it
  7. Run the code and it now works

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM