Last active
April 9, 2018 17:23
-
-
Save peterkellydev/e56be6f2f6f5b892d436c76c07fead34 to your computer and use it in GitHub Desktop.
simpleapi
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 bodyParser = require("body-parser"); | |
var app = express(); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.get("/", function(req, res) { | |
res.status(200).send("Welcome to our restful API"); | |
}); | |
var server = app.listen(3000, function() { | |
console.log("app running on port.", server.address().port); | |
}); | |
function sum(x, y) { | |
return x + y; | |
} | |
module.exports = sum; |
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 test = require("tape"); | |
var sum_test = require("../app.js"); | |
test("sum test", function(t) { | |
var s = sum_test(3, 4); | |
t.equal(s, 7); | |
t.end(); | |
}); | |
test("sum negative test", function(t) { | |
var s = sum_test(-3, -4); | |
t.equal(s, -7); | |
t.end(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment