Last active
November 27, 2019 02:34
-
-
Save mheadd/f2b7575ba1e6418b7b57442dc9ab9252 to your computer and use it in GitHub Desktop.
Hello world - Node.js, Express and COBOL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To try this, do the following on OS X:
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