# Tutorial: Hello World!
# Prerequisites
Hitchy is implemented in Javascript and requires Node.js (opens new window) as a runtime. In addition it relies on a tool called npm (opens new window) which is used to access a vast amount of packages ready for use. Hitchy is just one of those. This tool is included with Node.js.
# Create Project
- Create and enter new folder for your project:
mkdir hello-world && cd hello-world
- Initialize the project:
npm init
- Install Hitchy:
npm i @hitchy/core
# Configure Router
Create a sub-folder named config. Put a file named routes.js with the following content there:
exports.routes = {
"/": ( req, res ) => res.send( "Hello World!" ),
};
Important
The file's name doesn't matter much. The key routes
used for exporting in first line of file's content is essential though. We suggest name the file just like the exported configuration key to support long-term maintenance of code.
# Run Project
When in project folder enter
hitchy start
for running the project. This will display some URL to be opened in a web browser, like http://127.0.0.1:3000 (opens new window). Click on the URL or copy-n-paste it into your browser to get the desired output.
Stopping Hitchy
After starting hitchy the service is running in foreground. Log messages are printed on screen. If you want to stop hitchy just press Ctrl+C. This will gracefully shut down Hitchy.
# Dockerize Your Project
For production setup, we strongly suggest to put your project in a Docker (opens new window) container.
Create a file named Dockerfile in root folder of your project containing:
FROM node:lts-alpine COPY . /app RUN npm ci CMD ["npm", "run", "start:docker"] EXPOSE 3000
Create another file named .dockerignore in same folder with content:
node_modules
Open your project's package.json file. Look for the
scripts
section and add scriptstart:docker
as demonstrated:{ ... "scripts": { ... "start:docker": "hitchy start --ip=0.0.0.0" } ... }
Build the image to use on creating containers:
docker build -t name-of-your-project .
Optional: Publish your project by pushing the created image to a public container registry:
docker push name-of-your-project
After that you may run your service at any machine with docker engine installed. Create and run a container with:
docker run -d --restart always -p 3000:3000 name-of-your-project
# Dockerize Your Project
For production setup, we strongly suggest putting your project in a Docker (opens new window) container.
Create a file named Dockerfile in root folder of your project containing:
FROM node:lts-alpine COPY . /app RUN npm ci CMD ["npm", "run", "start:docker"] EXPOSE 3000
Create another file named .dockerignore in same folder with content:
node_modules
Open your project's package.json file. Look for the
scripts
section and add scriptstart:docker
as demonstrated:{ ... "scripts": { ... "start:docker": "hitchy start --ip=0.0.0.0" } ... }
Build the image to use on creating containers:
docker build -t name-of-your-project .
Optional: Publish your project by pushing the created image to a public container registry:
docker push name-of-your-project
After that you may run your service at any machine with docker engine installed. Create and run a container with:
docker run -d --restart always -p 3000:3000 name-of-your-project