Use your favorite package manager :
NPM
$ npm i galleonjs@latest
YARN
$ yard add galleonjs@latest
PNPM
$ pnpm add galleonjs@latest
Create a server.js
file and paste the code below to be able to run a basic http server on localhost:3000
import Galleon from "galleonjs"
const ship = new Galleon()
const PORT = 3000 || process.env.PORT
ship.get("/", (server) => {
server.send("Ahoy")
})
ship.listen(PORT,
_ => console.log(`http://localhost:${PORT}`))
finally run the server with
node server.js
GalleonJS is a minimal web development framework built on Node.js. It is designed to provide a simple and lightweight solution for building web applications. With Galleon, developers can easily create web pages and APIs by leveraging the power of Node.js and its vast ecosystem of modules. The framework is easy to learn, especially for those with previous experience with Node.js, and is well-suited for small to medium-sized projects. Galleon provides a flexible and modular architecture that allows developers to build their projects in the way that best suits their needs.
GalleonJS is built with almost zero-dependency, running with NodeJS standard library to make the project lighter, the Two main thing in this framework are The Galleon class
and the server object
• The Galleon class permits that you manage your routes and source your root directory (similar to static directory from expressjs)
• The server object has both Request and Response
methods from the http library with additionals features. So all the functions from node:http
tend to work properly
Sourcing works similar to express static, you have a folder with all your files, and not want to worry to route all the files with in that directory
ship.source("./public")
Adding this piece of code will souce the public
directory in your root directory
GalleonJS works with just two http methods GET and POST
To add a GET handler is just simple as
ship.get("/", (server) => {
server.send("ahoy")
})
Now the / or root
route can receive GET methods and respond to them
To add a POST handler is the same
ship.post("/api", (server) => {
if(server.body) console.log(server.body)
server.send("/api")
})
A differencial for POST handlers, is that he can have a body
object that can contains the data that you are trying to receive
Galleon also support simple dynamic routes, to add one:
ship.get("/api/:id",
(server) => {
const { id } = server.params
server.send(
`The id that you are searching is ${id}`
)
})
Galleon can also send JSON as a response
const emojis = [{
id: 1,
name: "Galleon",
emoji: "🚢"
},
{
id: 2,
name: "Pirate flag",
emoji: "🏴☠️"
}]
server.get("/emojis",
(server) => {
server.json(emojis)
})
Now you can provide apis using Galleon
If you want to send files as a response
ship.get("/",
(server) => {
server.sendFile(
"/index.html"
)
})
NOTE: this code just works if you have the index.html
in your root directory or set up your soucing folder
To redirect your user to another page
server.get("/secret",
(server) => {
server.redirect(
"/public"
)
})
SHHHH keep it secret