Last active
July 22, 2018 14:08
-
-
Save blackrabbit99/56cd3ee67628bce6213ad49bad550777 to your computer and use it in GitHub Desktop.
node_http.js
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
#!/usr/bin/env node | |
// simplest possible express app | |
var http = require('http'); | |
var express = require('express'); | |
var app = express(); | |
// while your program is running, requests to "/test" will trigger this | |
// callback function. | |
app.get("/test", function(req, res) { | |
// the "req" parameter is an object that gives you access to data in the | |
// request. | |
var message = req.query.message; | |
// the "res" parameter lets you manipulate the response. | |
res.end(message.toUpperCase()); | |
}); | |
// 4000 is the port. if you're running on your own computer, type | |
// http://localhost:4000/test?message=lowercase | |
// in the location bar. if you're on your digitalocean droplet | |
// (or whatever), go to | |
// http://SERVER-IP-ADDRESS/test?message=lowercase | |
// instead (replacing "SERVER-IP-ADDRESS" with your server's IP | |
// address or hostname. | |
http.createServer(app).listen(4000, function() { | |
console.log("Express server listening on port 4000"); | |
}); |
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": "http-server", "version": "0.0.1", "bin": "./index.js"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment