-
-
Save shotaK/a05e5251ba01eb4a0b85 to your computer and use it in GitHub Desktop.
Node.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
// --------------------------- create basic server --------------------------- \\ | |
var http = require("http"); | |
var myServer = http.createServer(function (request, response) { | |
response.writeHead(200, {"Content-type": "text/html"}); | |
response.write("<p><strong> hello </strong> batkan </p>"); | |
response.end(); | |
}); | |
myServer.listen(3000); |
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 app = express(); | |
app.get("/", function (req, res) { | |
res.send("<p>Hello World</p>"); | |
}); | |
// will get name as dynamic parameter | |
app.get("/user/:name", function (req, res) { | |
var name = req.params.name; | |
res.send("Hello: " + name); | |
}); | |
var server = app.listen(3000, function () { | |
var host = server.address().address; | |
var port = server.address().port; | |
console.log('Example app listening at http://%s:%s', host, port); | |
}); |
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
// --------------------------- install node packages --------------------------- \\ | |
// initial project initilization and generation of package.json file | |
npm init | |
// install without dependency in package.json file | |
npm install grunt | |
// install with adding dependency in package.json file | |
npm install grunt --save | |
// install with adding development dependency in package.json file | |
npm install grunt --save-dev | |
// install ejs templating engine | |
npm install ejs --save | |
// --------------------------- install/switch nodejs versions --------------------------- \\ | |
// check nodejs version | |
node --version | |
// install specific version of nodejs | |
nvm install 0.12 | |
// activate specific version of nodejs | |
nvm use 0.10 | |
// make specific nodejs version default | |
nvm alias default 0.12 | |
//install express framework | |
npm install express --save | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment