@kwruntime/core v2.0.11
kwruntime/core (2.x)
Major update for this project. The entire process of importing URLs, files, and other languages has been redesigned.
Features of kwruntime/core
- Allows importing URLs (in the style of Deno)
- Allows importing npm packages directly at runtime, even for ESM packages
- Built-in support for TypeScript and Civet
getting started
Install:
npx @kwruntime/core --install After installing, you can run any script in JavaScript/TypeScript/Civet with the command kwruntime
kwruntime /path/to/file.civetWithin node.js
const {kwruntime} = require("@kwruntime/core")
main()
async function main(){
const axios = await kwruntime.import("npm:axios@0.27.2")
const response = await axios("https://ipinfo.io")
console.info("Response:", response.data)
}or setting the execution to a file (similar result to how it would be executed in the terminal):
const {kwruntime} = require("@kwruntime/core")
// execute the file server.civet
kwruntime.main([process.argv[1], __dirname + "/server.civet"])Typescript and civet support
interface Person {
name: string;
age: number;
}
function greet(person: Person): string {
return "Hello, " + person.name + "!";
}
const alice: Person = {
name: "Alice",
age: 36
};
console.log(greet(alice));You can also write in Civet:
interface Person
name: string
age: number
function greet(person: Person): string
return "Hello, " + person.name + "!"
alice: Person :=
name: "Alice"
age: 36
console.log greet aliceOutput:
kwruntime test.civet
Hello, Alice!import from NPM packages, no need to install
Example: server.civet using express
express from "npm:express@4.18.2"
app := express()
app.get "/", (req, res): void =>
res.send "Welcome to the kwruntime!"
app.listen 8000
console.info "Server active"And test:
curl http://127.0.0.1:8080
Welcome to the kwruntime!import from URL
express from "https://esm.sh/express@4.21.2"
app := express()
app.get "/", (req, res): void =>
res.send "Welcome to the kwruntime!"
app.listen 8000
console.info "Server active"WARNING: Importing from esm.sh is a bit slow at the moment. It is recommended to import using npm as in the previous example.
Si quiere ver el progreso de la compilación de archivos typescript/civet, ajuste la variable de entorno DEBUG=1
DEBUG=1 kwruntime /path/to/file
And test:
curl http://127.0.0.1:8080
Welcome to the kwruntime!10 months ago
10 months ago
10 months ago
10 months ago
7 months ago
9 months ago
9 months ago
7 months ago
7 months ago
9 months ago
10 months ago
2 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago