From 979af1361f6fd44d05425dea6eb9e551bb9d2478 Mon Sep 17 00:00:00 2001 From: Samrith Shankar Date: Sat, 22 Feb 2020 11:43:56 +0100 Subject: [PATCH] Update examples README --- examples/express-javascript/README.md | 6 +- examples/express-typescript/README.md | 79 ++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/examples/express-javascript/README.md b/examples/express-javascript/README.md index 7d9826d..c062623 100644 --- a/examples/express-javascript/README.md +++ b/examples/express-javascript/README.md @@ -71,6 +71,6 @@ app.listen(process.env.PORT, () => { yarn start ``` -And, voila! Your Express server with the latest ES support is up and running! -You can make any changes and hit save, and check your terminal. Nodehawk will -promptly restart the process to reflect your changes! +Et voila! Your Express server with the latest ES support is up and running. You +can make any changes and hit save, and check your terminal. Nodehawk will +promptly restart the process to reflect your changes. diff --git a/examples/express-typescript/README.md b/examples/express-typescript/README.md index 8dcc490..4e4df7a 100644 --- a/examples/express-typescript/README.md +++ b/examples/express-typescript/README.md @@ -1 +1,78 @@ -COMING SOON! +# Express Typescript server with Nodehawk + +Creating an Express server written in Typescript from scratch, with Nodemon +watching for changes, is very simple. + +- Install express + +```bash +yarn add express +``` + +- Install development dependencies + +```bash +yarn add -D nodehawk typescript @types/express @types/node ts-node +``` + +- Create a `tsconfig.json` in your project root. + +```json +{ + "include": ["./src/**/*.ts", "./src/**/*.json"], + "exclude": ["node_modules"], + "compilerOptions": { + "baseUrl": "src", + "outDir": "build", + "rootDir": ".", + "module": "commonjs", + "target": "es2015" + } +} +``` + +- Create a `.nodehawkrc` in your project root. + +```jsonc +{ + "exec": "ts-node src/server", + "port": 1337 // this is optional. Default port is 4000. +} +``` + +- Create your server in `src/server.ts`. Not the usage of `process.env.PORT`. + This is very important to get the utmost out of Nodehawk. + +```typescript +import express from "express"; + +const app = express(); + +app.get("/", (req, res) => { + res.send("Hello world"); +}); + +app.listen(process.env.PORT, () => { + console.log(`App running on http://localhost:${process.env.PORT}`); +}); +``` + +- Add a script in your `package.json`. + +```jsonc +{ + "scripts": { + "start": "nodehawk" // Yes, really + } +} +``` + +- Run the script. + +```bash +yarn start +``` + +Et voila! Your Express server with the latest Typescript and ES support is up +and running. You can make any changes and hit save, and check your terminal. +Nodehawk will promptly restart the process to reflect your changes.