![]() For that the best practice will be to put them all in the _application folder. Now it's turn to put your business node code in the server. You can put you client side allication inside _public folder. You can put your index.html in _public folder and will display that in your browser. Now your projectFolder/_public location has become the index location. Here goes the code:Īpp.use(express.static(_dirname + '/_public')) // set the static files locationĬonsole.log("App listening on port " + port) To serve the static files you need to configure it with express. A http request for a file also considered as a routes and Node searched for the corresponding handling. Well after following all these steps, your folder will look like:īy default Node searches for corresponding routes when a request comes. There will also be a server.js file (I prefer to name it as "server.js", as it will handle the server configurations and also starts the server. Another folder is "_application", which will contain the core Node application, that handle routes, database connectivity, business logic etc. One named "_public", which is going to have all our client side files, i.e. Make your project folder and run the following two commands which will scaffold the app and install the express for you.Īfter executing the above commands your folder structure will be like the following. I'm assuming that you already know how to scaffold a Node app if not, go through our beginner's guide to Node.js. First, this is a rich module, which helps us to develop a complete application. We are preferring express for two reasons. Today we are gonna show you how to to setup a complete Node server using the most popular module of Node, that is express. There are several Node modules which do this work, like node-static, paperboy and http-server. Node provides very low level api thus it is very difficult to host your static files using only node.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |