If you run into troubles, got a suggestion, or issue, please e-mail editor@webtigerteam.com

# Node.JS

Node.JS is a open source JavaScript engine and library for creating high performance and scalable server apps and micro services.

## Running Node.JS via the editor

Open any JavaScript (node.js) file and press `F2` (or right click and select "Run nodejs script").

Press `F4` to stop the script.

### Via terminal emulator

If running the Node.js app via the editor doesn't work, try running it via the "Terminal emulator":
Right click and select "Terminal emulator".
In the terminal emulator type npm install (Press enter) and then node nameofapp.js (or npm start) (and press Enter).

## Prefer using unix sockets instead of ports

When using a unix socket (/home/username/sock/nameofapp) instead of port number, the app can be reached from http://nameofapp.username.domain.tld

Eg. replace server.listen(80) with server.listen("/home/username/sock/nameofsocket") in your Node.js app.

If you get Error: EADDRINUSE /home/username/sock/nameofsocket delete the unix socket before running server.listen().
The editor will automatically delete sockets files when the script exit, and also set process.env.PORT to the name of the project folder's name.

### Accessing TCP ports

If the app don't support unix sockets, then try with a regular port number.

Port numbers can be accesed from http://####.username.domain.tld (replace #### with the port number the app is listening to)

## Deploying to production

Window menu "Node.js" or keyboard `Ctrl + F2`.
This will copy the entire project into a production environment and (re)start the script.
(Make sure you test the script before deploying it.)

- `Ctrl + F2` deploy the script in "production".
- `Shift + Ctrl + F2` restart script "in production"
- `Ctrl + F4` stop the script "in production"
- `Shift + Ctrl + F4` remove the script from "production"

Production log files can be found in the log folder in your home directory.

### Production vs Development enviroment

The "production" enviroment will append prod: true, and myName: username to the process.env (enviroment variables).
Scripts started from the editor will have process.env.dev set to true.
This is useful if you for example want to use a different unix socket for production then in development. For example see: nodejs_examples/http_server/http_server_example.js

- ⬅Go back
- ⬆Index