Open Preview or Browser Programmatically


Is there a way to open a preview of a running application or browser window with code from within c9. so i usually code javascript nodejs and use a webpack dev server. there are a couple places to go and click a button to get either the preview within c9 or a full browser tab. just looking to add some code or a script somewhere just to save myself a click


To open preview you can use preview command

services.commands.exec("preview", null, {
    server: true,
    newTab: true

similar to

You can add code to your init script (which can be opened from cloud9 menu), what other actions do you want that code to perform?


cool. but this init code in the init script opens a preview window when i open my workspace. its cool that this works, but for example i want to do the following. i usually start my dev server from the command line with npm start, or whatever it happens to be. usually that command points to something like node index.js . i want to have the window open command executed during or directly after this.

how do i get commands or functions out of the init script and into the context of the workspace so i can call them whenever i want.


how do i make it so my postgresql database starts from the init script. right now i enter this in the command line to start it sudo service postgresql start


What workflow you want to have,
You either can create a bash script that runs your project and open a preview window with c9 command, or a button/shortcut/menu item in the ide that writes something in the terminal and opens the preview