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 click "Run nodejs script" in the menu).
Try any of the example files in the /nodejs/ folder.
Press F4 to stop the script.
Try via the terminal if you get errors
Right click and select "Terminal". In the terminal emulator type npm install and then node nameofapp.js (or npm start).
Replace port-nr with /sock/somename!
The cloud editor communicates with the Internet via unix sockets.
So instead of using for example port 80, use /sock/nameofsocket.
Eg. replace server.listen(80) with server.listen("/sock/nameofsocket")
All HTTP (and websocket) requests going to https://nameofsocket.username.webide.se will be proxied to your /sock/nameofsocket unix socket!
If you get Error: EADDRINUSE /sock/nameofsocket simply delete the file.
The editor will automatically delete sockets files when the script exit,
and also set process.env.PORT to the name of the project folder.
Deploying to production
The cloud editor makes it easy to deploy an app into production. Just press 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/ 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 sockets for production then in development.