--- title: SVR.JS can now do SCGI! date: 2023-08-11 03:26:06 tags: - cgi categories: - [News] - [Tips] --- **We have previously made SVR.JS run PHP-CGI and WordPress. Now SVR.JS - a web server software running on Node.JS can connect to SCGI (Simple Common Gateway Interface) servers.** We have developed a new mod to do that, [OrangeCircle](https://svrjs.org/dl/mods) (SCGI client written in JavaScript running on SVR.JS). SCGI (Simple Common Gateway Interface) is a protocol to interface web applications with HTTP servers, which is an alternative to CGI. It is similar to FastCGI, but it is easier to parse and implement. SCGI doesn't have interpreter invoking overhead, unlike CGI. This post will instruct you, how to set up SCGI web applications on SVR.JS. ## Setting up SCGI on server-side First of all, [download](https://svrjs.org) and install SVR.JS web server. You can also use `create-svrjs-server` tool or [SVR.JS installer](https://svrjs.org/dl/installer) to install SVR.JS. After setting up SVR.JS, download and install [OrangeCircle](https://svrjs.org/dl/mods) to *mods* directory. After installing OrangeCircle SCGI client, create *orangecircle-config.json* file in SVR.JS installation directory, and configure it like this: ```json { "path": "/helloworld", "host": "127.0.0.1", "port": 4000 } ``` Adjust your mount path, SCGI server host and port settings according to your needs. After setting up and configuring SCGI client, run SVR.JS using `node svr.js` or `bun run svr.js` and visit SCGI page (for example http://localhost/helloworld). You will then see this error page: ![503 Service Unavailable page displayed when trying to connect to SCGI server](/images/scgi-client-error.png) This is because we didn't set up SCGI server yet. **But we have set up SCGI client!** We need to just set up SCGI server... ## Setting up SCGI server To set up SCGI server, first create *scgi-server* directory outside SVR.JS installation directory, and change your working directory to new one. Then install SCGI server module using `npm install scgi-server` (*scgi-server* package is deprecated; we're using it just for example SCGI application) command. After installing SCGI server module, create *index.js* file with those contents: ```js var SCGIServer = require('scgi-server'); var server = SCGIServer(4000); server.on('request', function(error, socket, headers, data) { if (error) { console.error("received invalid scgi request"); return; } socket.write("Status: 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n\r\n"); socket.write("