Getting Started with Express / Node.js Cheatsheet

Create package.json in directory
npm init
npm install –save express (if from existing repo, use npm install)

Template for main.js
var express = require("express");
var app = express();

app.use(
    express.static(__dirname + "/public")
);

app.use("/index.html", function(req, res) {
    res.status(200);
    res.type("text/html");
});

port = 3000;
if (process.argv[2]) {
    port = +process.argv[2];
}

app.listen(
    port,
    function() {
        console.log("application started on port %d", port);
    }
);
Install NodeMon
sudo npm install -g nodemon


Start Server
nodemon index.js


Kill Server
ctrl-C


Install browser-sync (nodemon for HTML)
sudo npm install -g browser-sync
browser-sync start -s -f ‘*.html’ ‘*.js’

Leave a Reply

Your email address will not be published. Required fields are marked *