Skip to content
MikeKlemarewski edited this page Jun 20, 2012 · 17 revisions

install express manually

npm install express

install express using package.json

Create a file called package.json

{
    "name":"demo-application-name"
    , "author":"Izzak Schroeder <[email protected]>"
    , "version":"0.0.1"
    , "main": "index.js"
    , "dependencies":{
        "express":">=2.5.10"
    }
}

Note: You should only specify modules necessary to run the application in dependencies. All other helper modules such as unit testing modules should be specified in a "devDependencies" section. These dev dependencies can be installed by executing the command:

npm -dev install

To install all necessary dependencies, execute: npm install

for more info, type

npm help

or visit: http://npmjs.org/doc/json.html

Creating a index.js for basic express framework and export it

var server = require('express').cerateServer();

server.get("/", function (request, response) {
    response.writeHead(200, {"Content-type":"text/plain"})
    response.end('whatever you want ');
})

module.exports = server;

Create another file called test.js, so we can load index.js into it and use it

var
    yourServer = require('./demo-application-name'),
    server = require('express').createServer();

server.use('/izaak', yourServer);
server.listen(8888);

rename the folder to the name in your package.json

in this case, use demo-application-name, move test.js out side the folder.

now let's publish it to NPM

npm adduser just follow the guides and should be good

go into your module folder

type

npm publish

go up one level

npm install demo-application-name

now you can var Server = requare("demo-application-name") in your application

now let's update your module!

  1. change the version to a higher level

  2. then use npm publish again.