Skip to content

Instantly share code, notes, and snippets.

@mheadd
Last active November 27, 2019 02:34
Show Gist options
  • Save mheadd/f2b7575ba1e6418b7b57442dc9ab9252 to your computer and use it in GitHub Desktop.
Save mheadd/f2b7575ba1e6418b7b57442dc9ab9252 to your computer and use it in GitHub Desktop.
Hello world - Node.js, Express and COBOL
IDENTIFICATION DIVISION.
PROGRAM-ID. CLIOPTIONS.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 argv pic x(100) value spaces.
PROCEDURE DIVISION.
ACCEPT argv FROM argument-value
DISPLAY "<h2>Hello, " argv "!</h2>"
STOP RUN.
var express = require('express');
var Cobol = require('cobol');
var app = express();
var port = process.argv[2] || 3000;
app.listen(port);
app.get('/hello', function (req, res) {
var name = req.query.name || 'Anonymous person';
Cobol('./hello.cbl', {
args: [name]
}, function (err, data) {
if(err) {
res.status(500).send('I hate to be rude, but there was an error: ' + err);
}
else {
res.send(data);
}
});
});
{
"name": "cobol-example",
"version": "0.0.1",
"description": "This is an example app using node cobol.",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Mark Headd <[email protected]> (http://civic.io/)",
"license": "CC0",
"dependencies": {
"cobol": "^1.5.1",
"express": "^4.13.4"
}
}
@mheadd
Copy link
Author

mheadd commented Apr 12, 2016

To try this, do the following on OS X:

~$ brew install gnu-cobol
~$ git clone https://gist.github.com/mheadd/f2b7575ba1e6418b7b57442dc9ab9252 && cd f2b7575ba1e6418b7b57442dc9ab9252
~$ npm install
~$ npm start

Open your web browser to http://127.0.0.1:3000/hello. Adding a query string parameter for name makes it personal.

http://127.0.0.1:3000/hello?name=Big%20fella

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment