forked from newrelic/newrelic-node-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEWRELIC-7888: (nestjs) add a Nest.js example app
This is a basic Nest.js app using Prisma for the database and Winston for logging. It exercises several features of Nest.js like interceptors and guards. Like other examples here, it can be run in Docker. Optionally, via NES_USE_FASTIFY envvar, it may use Fastify, but it defaults to Express, as that's Nest.js's default.
- Loading branch information
Jordi Gutiérrez Hermoso
committed
Apr 19, 2023
1 parent
32eff05
commit c5fe42f
Showing
32 changed files
with
10,111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ newrelic_agent.log | |
.idea | ||
dist | ||
**/*.log | ||
|
||
# For custom environment | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM node:lts-slim | ||
EXPOSE 3000 | ||
|
||
RUN apt-get update && apt-get install httpie jq -y | ||
|
||
WORKDIR /app | ||
COPY app . | ||
COPY entrypoint.sh /entrypoint.sh | ||
RUN npm ci | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This is an example of an instrumented Nest.js app, using Prisma and Winston. | ||
|
||
Get it running: | ||
|
||
1. Copy sample.env to .env | ||
2. Edit .env to add your New Relic ingest key, and any other desired changes. | ||
3. Start with `docker-compose up --build`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
tsconfigRootDir: __dirname, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint/eslint-plugin'], | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:prettier/recommended', | ||
], | ||
root: true, | ||
env: { | ||
node: true, | ||
jest: true, | ||
}, | ||
ignorePatterns: ['.eslintrc.js'], | ||
rules: { | ||
'@typescript-eslint/interface-name-prefix': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
pnpm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# OS | ||
.DS_Store | ||
|
||
# Tests | ||
/coverage | ||
/.nyc_output | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
## Description | ||
|
||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. | ||
|
||
## Installation | ||
|
||
```bash | ||
$ npm install | ||
``` | ||
|
||
## Running the app | ||
|
||
```bash | ||
# development | ||
$ npm run start | ||
|
||
# watch mode | ||
$ npm run start:dev | ||
|
||
# production mode | ||
$ npm run start:prod | ||
``` | ||
|
||
## Test | ||
|
||
```bash | ||
# unit tests | ||
$ npm run test | ||
|
||
# e2e tests | ||
$ npm run test:e2e | ||
|
||
# test coverage | ||
$ npm run test:cov | ||
``` | ||
|
||
## License | ||
|
||
Nest is [MIT licensed](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
shopt -s expand_aliases | ||
|
||
# https://stackoverflow.com/a/62087619/11352427 | ||
randomString() { | ||
local length=$1 | ||
LC_ALL=C tr -dc A-Za-z0-9 </dev/urandom | head -c $length | ||
} | ||
|
||
# Make sure httpie can work in a script | ||
alias http='http --print b --ignore-stdin' | ||
beauty="CatsArePretty" | ||
|
||
echo "Starting request loop" | ||
while true; do | ||
name=$(randomString 10) | ||
email=${name}@example.com | ||
echo "Creating a user" | ||
http post http://localhost:3000/user name=${name} email=${email} | tee json | jq -C | ||
user_id=$(jq .id json) | ||
|
||
echo "Say hello" | ||
http get http://localhost:3000/ | ||
|
||
echo "Show this user" | ||
http get http://localhost:3000/user/${user_id} | jq -C | ||
|
||
echo "Creating two cats" | ||
http post http://localhost:3000/cat name=$(randomString 20) birthdate=2023-04-01 ownerEmail=${email} breed=${beauty} | tee json | jq -C | ||
cat_id_1=$(jq .id json) | ||
http post http://localhost:3000/cat name=$(randomString 20) birthdate=2023-04-01 ownerEmail=${email} breed=${beauty} | tee json | jq -C | ||
cat_id_2=$(jq .id json) | ||
|
||
echo "Find the cats" | ||
http get http://localhost:3000/filtered-cats/${beauty} | jq -C | ||
|
||
echo "Find the cats, but rudely, get denied access" | ||
http get http://localhost:3000/filtered-cats/${beauty}?please=no | jq -C | ||
|
||
echo "Find a cat but wrongly, trigger a Nest.js error" | ||
http get http://localhost:3000/cat/felix | jq -C | ||
|
||
echo "Delete the cats" | ||
http delete http://localhost:3000/cat/${cat_id_1} | jq -C | ||
http delete http://localhost:3000/cat/${cat_id_2} | jq -C | ||
sleep 5 | ||
|
||
echo "Delete the user" | ||
http delete http://localhost:3000/user/${user_id} | jq -C | ||
sleep 5 | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/nest-cli", | ||
"collection": "@nestjs/schematics", | ||
"sourceRoot": "src", | ||
"compilerOptions": { | ||
"deleteOutDir": true | ||
} | ||
} |
Oops, something went wrong.