@@ -236,4 +236,67 @@ you can see it in browser as.
236236<img src =" https://github.com/getmscode2013/NodeJsTutorial/blob/master/day11-ExpressAppGenerator/screen.png " >
237237
238238
239+ # Day 12 - Expressjs Inclusing Static Files
240+
241+ 1 . While creating the application we need to include many Static files like Images, CSS , JS etc.
242+
243+ 2 . In NODEJS for express it will provide the middleware to create access the static file.
244+
245+ 3 . If you will not include the middleware, it will not show the static file you included to project.
246+
247+ 4 . Lets include express js in application similar way we did it on day 10
248+ // npm install express --save
249+
250+ 5 . Lets create folder starature with the name assets and having sub folder. <br / >
251+ - Images : It contain images.
252+ - style : In contains Style sheet
253+
254+ 6 . We will keep our static file there
255+
256+ 7 . Lets see HTML file structure with Image and CSS.
257+
258+ <b >index.html </b >
259+
260+ ===========================
261+ html <br />
262+ title<br />
263+ My static Page
264+ /title<br />
265+
266+ head<br />
267+ link rel="stylesheet" href="/Css/style.css"<br />
268+ /head<br /><br />
269+
270+ body<br />
271+ table<br />
272+ tr<br />
273+ td class="tableBody" images about the timer control /td<br />
274+ td img src="/images/iconfinder_tower_748987.png" width=100 /td<br />
275+ /tr<br />
276+ /table<br /><br />
277+
278+ /body<br /><br />
279+
280+ /html<br />
281+
282+ 8 . Now include the middleware component in Index.js as below.
283+
284+ Index.js
285+
286+ ======
287+ const ex = require("express");
288+ const app = ex();
289+
290+ <b >app.use(ex.static('assets')) </b >
291+
292+
293+ // to include file we need to use sendfile and add the file name
294+ app.get('/', (req, res) => { res.sendfile("index.html"); })
295+
296+
297+ app.listen("4000", () => console.log("Server is running on port 4000"));
298+
299+ 9 . Output you will get in the screen as.
300+
301+ <img src =" https://github.com/getmscode2013/NodeJsTutorial/blob/master/day12-StaticFiles/staticoutput.png " >
239302
0 commit comments