0

I am familiar with Java web containers, where web applications are deployed as war files.

I am confused how to deploy CSS, JS, HTML, images (and so on) in Node.js. How does one do this?

I have very limited knowledge of Node.js. Thanks in advance!

Zearin
  • 1,474
  • 2
  • 17
  • 36
Preethi
  • 2,112
  • 7
  • 38
  • 54
  • 1
    Try using [express](http://expressjs.com/) – Raynos Aug 12 '11 at 21:47
  • Take a look at this example to create a node server for serving static files: https://gist.github.com/701407 – Jørgen Aug 12 '11 at 22:25
  • thanks all . though i am not very clear since i am used .war . I am assuming the folder structure is of xxx.js format – Preethi Aug 12 '11 at 22:40
  • 1
    @Preethi I use [this structure](https://github.com/Raynos/raynos-blog) for my own blog – Raynos Aug 12 '11 at 23:09
  • Thanks Raynos , i understand . Any idea on various frameworks available with node.js ? I need to talk with SQL db and i am not sure the existing node.js supports that . Jorgen had mentioned about "expresso" which looks interesting – Preethi Aug 12 '11 at 23:12
  • @Preethi come talk to the guys [node.js chat](http://chat.stackoverflow.com/rooms/642/node-js) – Raynos Aug 12 '11 at 23:21

1 Answers1

5

http://expressjs.com/

http://expressjs.com/guide.html#configuration

app.js

app.configure(function(){
  var oneYear = 31557600000;
  app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
  app.use(express.errorHandler());
});

app.listen(8888);

index.html

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="css/index.css">
    </head>
    <body>
        <span class='hello'>Hello world!</span>
    </body>
</html>

index.css

.hello { color: green; }

Directory structure:

project/
    app.js
    public/
        index.html
        css/
            index.css

Run your app: node app.js

Go visit your website: http://localhost:8888

The directory and file names are arbitrary. Everything is configurable, nothing is complicated. Nobody's trying to keep you tied to a specific directory structure or naming scheme in node, generally speaking.

Go get em, tiger.

Josh
  • 12,602
  • 2
  • 41
  • 47