-
安装Hysteria: 使用npm安装Hysteria模块:
npm install hyper
这将将Hysteria安装到你的项目目录下。
-
创建项目文件: 在你的项目目录下创建或更新
package.json文件,添加以下内容:{ "name": "hysteria-example", "version": "1..", "description": "Hysteria Node.js server example", "scripts": { "start": "hyper start" }, "config": { "port": 800, "https": true } } -
编写入口文件: 在项目目录下创建
main.js文件:const hyper = require('hyper'); hyper.run({ server: 'server.js', bind: '...', port: 800, https: true, cert: 'your-ssl-cert.pem', key: 'your-ssl-key.pem' });或者更简单地:
const hyper = require('hyper'); hyper.run(main => { main.get('/').send('Hello, World!'); }); -
运行服务器: 使用以下命令启动Hysteria服务器:
npm start
或者使用命令行工具:
hyper run main.js
-
访问服务器: 打开浏览器,访问
http://localhost:800或https://localhost:800,如果启用了HTTPS。 -
高级配置:
- 绑定地址:在
package.json的config中设置bind选项。 - HTTPS:在
config中设置https为true,并生成SSL证书:hyper cert create --common-name "your-domain" -o cert.pem -o key.pem
- 启动命令:使用
--bind和--cert参数:hyper run main.js --bind 0... --cert cert.pem --key key.pem
- 绑定地址:在
通过以上步骤,你可以成功配置并运行Hysteria节点,满足开发和生产环境的需求。









