First thing to do is to install node and npm, obviously, but assuming that is done, go and create a folder and put a git repository on it (init, use github, .gitignore swap files, etc).
Next, call npm init, which is going to populate package.json for you. You can start installing plug-ins once you've done this. I'm not too sure what plug-ins I need for now, but at least let's use
$ npm install express --saveSince I'm going to use Heroku, here's their version of hello world, which I'm calling app.js:
var express = require('express'); var app = express(); app.set('port', (process.env.PORT || 5000)); app.use(express.static(__dirname + '/public')); app.get('/', function(request, response) { response.send('Hello World!'); }); app.listen(app.get('port'), function() { console.log("Node app is running at localhost:" + app.get('port')); });Follow the starting steps on Heroku website, but most importantly, create a file called Procfile containing the one liner (telling the server what to run at start)
web: node app.jsYou can also run the server locally using
$ foreman start web
... and that's it, should be up and running online.
No comments:
Post a Comment