NodeJS on devweb #
When your NodeJS container is auto-provisioned, an example app will be copied to your ~/DEVWEB/2023/nodejs folder. The example app will be called testapp.
You'll also find a file named NODEJS. This is the app server control file. The control file should contain one line with the name of the app folder; for the example app, the NODEJS file contains "testapp" (corresponding to the example app folder name).
If you want to retain the example app code and structure for reference, but also want to create a new app alongside it, you should:
- Create a new folder
- Run npm init (use the npm alias that corresponds to the current version, e.g. npm18)
- Run npm install to install your dependencies
- Put the app name into the NODEJS control file:
mkdir ~/DEVWEB/2023/nodejs/mynewapp cd ~/DEVWEB/2023/nodejs/mynewapp npm18 init npm18 install ionic express cordova echo mynewapp > ~/DEVWEB/2023/nodejs/NODEJS
You should be able to test your app by running node locally, e.g.
node18 testapp. You can then browse to http://localhost:3000/ to view it; if you are working on cafe (rather than a lab PC or CPU node), you may need to create an ssh tunnel (e.g.
ssh -L 3000:localhost:3000 cafe.cis.strath.ac.uk).
Important notes #
- Your app must be configured to listen on port 3000.
- Your app must be configured to listen on interface "0.0.0.0" - this is important so that our reverse proxy can connect the service inside your container. If this is configured incorrectly, you might see errors like ERR_HTTP2_PROTOCOL_ERROR in your browser.
- The packages.json file must refer to the main file correctly, e.g.
"main": "app.js", otherwise the NodeJS application will not start.
- To view your app, visit https://devweb2023.cis.strath.ac.uk/username-nodejs/
- You can only have one NodeJS app at a time.
- The container running your app will stop running after 30 minutes (from when it was first started). It will restart upon next access. Logging to any file in /home/$USER/DEVWEB/2023/.logs/nodejs will refresh the timer, allowing you to keep your container awake for 30 minutes from the last access.
- You can restart your app, picking up any changes to your code, by updating the control file, e.g.
touch /home/username/DEVWEB/2023/nodejs/NODEJS; the app server will restart within 30 seconds.
Debugging issues #
If you've copied your code to your NodeJS folder but your app doesn't seem to be running, please check the logs in /home/$USER/DEVWEB/2023/.logs/nodejs for a clue as to what has gone wrong.