Skip to content

Instantly share code, notes, and snippets.

@frontend-gist
Last active August 29, 2015 14:24
Show Gist options
  • Save frontend-gist/e0d3cac51c69c9181b9d to your computer and use it in GitHub Desktop.
Save frontend-gist/e0d3cac51c69c9181b9d to your computer and use it in GitHub Desktop.
Node.js
// --------------------------- 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);
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);
});
// --------------------------- 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