Node.js can run fairly well on Toolforge including with websocket support by running the following steps.
ConventionsThe Toolforge toolforge webservice
command starts node.js web servers using convention rather than configuration. These conventions are expected by the Toolforge tooling:
npm start
from the tool's $HOME/www/js directory must start the web server.
var http = require('http'); var port = parseInt(process.env.PORT, 10) ; // IMPORTANT!! You HAVE to use this environment variable as port! http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(port);
$HOME/www/js/server.js
.npm start
is executed. The default way to do this is to name your main script server.js
.PORT
). You can access this via process.env.PORT
. Without this, your tool will not be found by the Nginx proxy.The toolforge-node-app-base template repository is available on GitHub which has the above-mentioned setups already done and some further boilerplate code, which can be used to get started quickly.
Deploying a Vue JS Application using Node JS and Vite$HOME/www/js
directory. If the directory doesn't exist, feel free to create it using the mkdir command. Ensure that the project is cloned such that the package.json is in the www/js directory using git clone https://YOUR_PROJECT_URL .
"start": "npm install && npm run build && node server.js"
$HOME/www/js
directory using nano server.js
.import express from "express"; const app = express(); const PORT = parseInt(process.env.PORT, 10); // IMPORTANT!! You HAVE to use this environment variable as port! app.use(express.static("dist")); app.listen(PORT, () => console.log(`Server listening on port: ${PORT}`));
toolforge webservice node20 start
toolforge webservice node20 logs
https://YOUR_TOOL_NAME.toolforge.org
The webservice command accepts the following parameters:
toolforge webservice node20 start|stop|restart|shell|logs
$HOME/www/js
in your tool's home directory.toolforge webservice node20 start
.
$HOME/www/js/package.json
containing the text:{ "scripts": { "start": "node server.js" } }
toolforge webservice node20 restart
.kubectl get pods
.kubectl logs -f $MY_POD_NAME
.To use an up-to-date version of node, e.g. for installing dependencies, run:
toolforge webservice node20 shell
cd $HOME/www/js
npm install
If you need to use other versions of node, you can use nvm or a similar tool to install node versions locally.
To activate the version, define the start
property of the scripts
object in your package.json
file to activate the needed version before starting your app. In its simplest form it could look like "scripts": {"start":"nvm run node server.js"}
.
npm install
, try LINK=g++ npm install
kubectl
executable, could it be that you started a webservice shell and didn't exit
it?Support and administration of the WMCS resources is provided by the Wikimedia Foundation Cloud Services team and Wikimedia movement volunteers. Please reach out with questions and join the conversation:
Use a subproject of the #Cloud-Services Phabricator project to track confirmed bug reports and feature requests about the Cloud Services infrastructure itself
See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4