1.0.2 • Published 4 years ago

serve-static-file v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

serve-static-file

Install

npm install serve-static-file

Usage

const http = require('http');
const serve = require('serve-static-file');

const port = 3000

const server = http.createServer((req, res) => {
    if (req.url === '/' || req.url === '/index.html') {
        serve(res, 'index.html', (err) => {
            if (err) throw err;
            // Callback Function
        })
    } 
    else if (req.url === 'script.js') {
        serve(res, 'script.js', (err) => {
            if (err) throw err;
            // Callback Function
        })
    }
    else {
        res.end('404 Not Found')
    }
});

server.listen(port, () => {
    console.log(`Server running on port ${port}`);
})

NOTE: The first paramter must be the response object. This API does not need the request object.

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago