sorry this is a very basic question. I wrote some functions to handle requests by passing a callback to http.createServer
. The functions work if I import them directly from the functions.js file like in this code.
import {handle_request} from './functions.js';
import http from 'http';
http.createServer(handle_request).listen(8080);
Now I want to put this in a package, so that I can install the libraries my code depends on automatically with npm install. My package.json
looks like this, I can install the package and I's found in the node REPL, but how do I actually call the functions in the package or use them as callbacks?
{
"name": "package_name",
"version": "1.0.0",
"description": "posts images to a slack channel",
"main": "functions.js",
"author": "me",
"dependencies": {
"mustache": "*"
},
"type": "module"
}
The functions are defined like this:
export var handle_request = function (req, res) {
// function body ...
}
I think my problem is either the import statements in the script that calls the library or some missing exports in the package.
Sorry again for the very basic question, I found many posts and documentations on npm packages but nothing solving my problem. Any help appreciated.