Ref:
Assumption: npm, node, express got installed before this step!
1. Create nodejs project folder
2. Create package.json
{ "name": "express-static-files-example", "version": "0.0.1", "description": "A sample code project demonstrating serving static files using express", "dependencies": { "express": "*" }, "scripts": { "start": "node server.js" } }
3. Create server.js
var express = require('express'); var app = express(); app.use(express.static(__dirname + '/public')); app.listen(80);
4. Put all your HTML, javascript, and css files inside the public folder
npm install
npm start
No comments:
Post a Comment