nestjs / docs.nestjs.com Goto Github PK
View Code? Open in Web Editor NEWThe official documentation https://docs.nestjs.com π
License: MIT License
The official documentation https://docs.nestjs.com π
License: MIT License
I'd like to show my approach for creating a ConfigService component. If you are interested I could enhance the current config tutorial, so that users can add the below features step by step. The advantages using my suggestion:
@Component()
export class ConfigService {
public env: string;
constructor(path: string) {
dotenv.config({ path });
const processEnv: NodeJS.ProcessEnv = this.validateInput();
this.initializeClassProperties(processEnv);
}
/**
* Initializes the class properties with the passed values
* @param processEnv The process environment variables
*/
private initializeClassProperties(processEnv: NodeJS.ProcessEnv): void {
this.env = processEnv.NODE_ENV;
}
/**
* Ensures all needed variables are set and returns the process environment
*/
private validateInput(): NodeJS.ProcessEnv {
const envVarsSchema: Joi.ObjectSchema = Joi.object({
// General
NODE_ENV: Joi.string()
.valid(['development', 'development-verbose', 'production', 'test', 'provision'])
.default('development')
})
.unknown()
.required();
const { error, value: envVars } = Joi.validate(process.env, envVarsSchema);
if (error) {
throw new Error(`Config validation error: ${error.message}`);
}
return envVars;
}
If you approve I'll submit a pull request for enhancing the config service providers with these features?
The sample for use the new gRPC Microservice isn't working.
Sample:
https://github.com/nestjs/nest/tree/master/sample/04-grpc
Error:
yarn start
yarn run v1.5.1
$ ts-node src/main.ts
/Users/javierdiaz/coderdiaz/github/nestjs-grpc/node_modules/ts-node/src/index.ts:330
throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset))
^
TSError: β¨― Unable to compile TypeScript
src/hero/hero.controller.ts (20,11): Argument of type '{ transport: Transport; options: { package: string; protoPath: string; }; }' is not assignable to parameter of type 'ClientOptions'.
Type '{ transport: Transport; options: { package: string; protoPath: string; }; }' is not assignable to type 'TcpClientOptions'.
Types of property 'transport' are incompatible.
Type 'Transport' is not assignable to type 'Transport.TCP'. (2345)
at getOutput (/Users/javierdiaz/coderdiaz/github/nestjs-grpc/node_modules/ts-node/src/index.ts:330:15)
at Object.compile (/Users/javierdiaz/coderdiaz/github/nestjs-grpc/node_modules/ts-node/src/index.ts:516:11)
at Module.m._compile (/Users/javierdiaz/coderdiaz/github/nestjs-grpc/node_modules/ts-node/src/index.ts:403:43)
at Module._extensions..js (module.js:584:10)
at Object.require.extensions.(anonymous function) [as .ts] (/Users/javierdiaz/coderdiaz/github/nestjs-grpc/node_modules/ts-node/src/index.ts:406:12)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
error An unexpected error occurred: "Command failed.
Exit code: 1
Command: sh
Arguments: -c ts-node src/main.ts
Directory: /Users/javierdiaz/coderdiaz/github/nestjs-grpc
Output:
".
info If you think this is a bug, please open a bug report with the information provided in "/Users/javierdiaz/coderdiaz/github/nestjs-grpc/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Nest: v5.0.0-beta.6 and v5.0.0-rc.2
Yarn: v1.5.1
Platform: Mac
The sample is outdated?
Thanks :)
Are there any relevant examples?
Hi Kamil,
I was wondering what's the approach you'd like people to follow when translating the doc into different languages.
So far I've seen the content is part of the html part of the component.
Should we create the translated version of the doc as an independent ng project in a different branch and then send a PR?
Let me know what is the approach you'll like people to follow when delivering the translated versions of the site.
Best,
Chris.
Add documentation version switcher to the menu, something similar the other frameworks already do, below are examples from bootstrap and angular documentation.
I also noticed there is v4 link in v5 dev branch but there is no link from v4 to latest, also there is no exact version shown in documentation that could be used as a good reference - v4.6.6 or v4.6.x would be better then just v4.
[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
As a user, I would like to see a list of companies that use Nest in their production projects.
For Tooling issues:
- Node version: XX
- Platform:
Others:
[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
For Tooling issues:
- Node version: XX
- Platform:
Others:
It would be nice if headers would be linkable, like the way it's done on github markdown. It would help out a lot when you want to show someone a section of documentation. Not you have to tell them to scroll down, but then you could just link them to that section.
In the pipe doc under A built-in ValidationPipe, the text talks about enabling transformation:
However, if you want the pipe to mutate the payload, you can configure it by passing appropriate options:
But the code has transformation disabled:
@UsePipes(new ValidationPipe({ transform: false }))
The source code for the doc explicitly calls the code for createCatsControllerParamPipeTransformFalse
. So I am unsure whether there is a reason for the code to be this way. If the code is meant to be this way, then the text should reflect that the code does not transform.
But personally, I would prefer changing the code to show transformation, since that wasn't happening in the doc before.
[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
As a user, I would like to see Compression section
For Tooling issues:
- Node version: XX
- Platform:
Others:
I am unable to access https://docs.nestjs.com/
kindly let me know when this page will be available or if it has moved to another page.
[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
As a user, I would like to see Security chapter.
For Tooling issues:
- Node version: XX
- Platform:
Others:
Here is the demo code in techniques/database section :
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'mysql',
host: 'localhost',
port: 3306,
username: 'root',
password: 'root',
database: 'test',
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
synchronize: true,
}),
],
})
export class ApplicationModule {}
the entity
configuration should be:
// delete the /..
entities: [__dirname + '/**/*.entity{.ts,.js}'],
delete ../
for purpose when run node dist/main.js
, it will look for entity files from the root directory, and will find *.entity.ts files located in src
, then it will cause buid failed such as
[Nest] 26420 - 2018-6-13 17:17:19 [TypeOrmModule] Unable to connect to the database. Retrying (1)... +1284ms
error stack shows: unexpected token import in xxx.entity.ts
[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
For Tooling issues:
- Node version: XX
- Platform:
Others:
[x] Regression
[ ] Bug report
[ ] Feature request
[] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
For Tooling issues:
- Node version: XX
- Platform:
Others:
The issue I have found is not made apparent until the e2e tests are run.
It is not made clear in the documentation (https://docs.nestjs.com/techniques/mvc) where the "views" and the "public" folders should be created. I assumed that they should both go into "src" folder because main.ts is located in "src" and it refers to 'public' and 'views' when it performs a 'join'.
When you run the e2e tests (npm run test:e2e) you see a message similar to this:
[Nest] 20785 - 2018-6-13 15:31:19 [ExceptionsHandler] ENOENT: no such file or directory, open '/Users/Plastikfan/dev/git/citrus/seed/adminpro-nest/nest-server/src/views/index.hbs'
I changed main.ts to the following (assuming that "public" and "views" are in project root and not "src"):
async function bootstrap() {
const app = await NestFactory.create(AppModule, new FastifyAdapter());
app.useStaticAssets({
root: join(__dirname, '../public'), // NB: ../
prefix: '/public/',
});
app.setViewEngine({
engine: {
handlebars: require('handlebars'),
},
templates: join(__dirname, '../views'), // NB: ../
});
await app.listen(3000);
}
[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
No docs
I would like to see GCP/AWS/Azure (basically serverless) documentation.
For Tooling issues:
- Node version: XX
- Platform:
Others:
[ ] Regression
[ ] Bug report
[ ] Feature request
[ ] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
As a user, I would like to have an easy access to menu/next article on mobile.
For Tooling issues:
- Node version: XX
- Platform:
Others:
when the chapter about graphql is available on docs.nestjs.com?
Referring to an issue that I have incorrectly placed in the framework repo.
[ ] Regression
[ ] Bug report
[ ] Feature request
[X] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
It is unclear which behaviour to use for serving an Angular app with routing. Should I use a *
path controller as the last on in the array of controllers and do a res.sendFile
to serve the index.html
file or should I use a HttpExceptionFilter
to res.sendFile
the index.html
file whenever the path is unresolved?
Using the HttpExceptionFilter
filter seems like a logical choice, because of Angular needing access to other static files. This should be clearly laid out in the documentation in my opinion.
Basically: Have a distinct pattern to serve an Angular application, since this framework is very friendly with Angular.
NestJS 5.0.0
When scrolling on mobile with the menu open, the menu closes automatically.
[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Hi guys, would you be ok with me adding my config module into your documentation? Alongside your current env documentation of course. I'm also willing to transfer ownership of the repo to nestjs if you would like it? https://github.com/nestjs-community/nestjs-config
I also want to add some decorators to it so it would look a bit more like this when using the config module opposed to what is in the readme right now.
@Controller()
@Configurable() //possibly needs a better name
export default class UserController {
index(@ConfigParam('APP_TEST') test: string) {
return test;
}
}
I also think it would be cool to add it to the starters repos to enable configuration of the port.
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const config = app.get(ConfigService);
await app.listen(config.get('APP_PORT'));
}
bootstrap();
[ ] Regression
[ ] Bug report
[ ] Feature request
[ X ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
I followed the new unit test documentation for typeorm:
https://docs.nestjs.com/techniques/database
at the end of doc there is a link to example:
https://github.com/nestjs/nest/tree/master/sample/05-sql-typeorm
but the class test are missing
It would be useful to have a complete example on how to implement unit test for different scenario.
I tried to create an example with a unit test a bit more complex but I can not understand how I can declare the dependency of shared service in Test.createTestingModule
https://github.com/mmenik/nest-unit-test.git
Nest version: 5.0.1
For Tooling issues:
- Node version: v9.11.1
- Platform: Windows
Others:
[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
nestjs/nest#706
nestjs/nest#717
For Tooling issues:
- Node version: XX
- Platform:
Others:
[ ] Regression
[ ] Bug report
[ ] Feature request
[ ] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Update Microservices -> Custom Transport
to the latest Nest version.
For Tooling issues:
- Node version: XX
- Platform:
Others:
[ ] Regression
[ ] Bug report
[ ] Feature request
[ ] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
For Tooling issues:
- Node version: XX
- Platform:
Others:
The FAQ -> Examples link in the menu points to https://github.com/nestjs/nest/tree/master/examples instead of https://github.com/nestjs/nest/tree/master/sample
Edit: Apparently this only affects the v4 documentation. I assume it's going to be replaced by the v5 documentation very soon anyways.
we are planning to use nest js framework for middleware application using node js and typescript. i would like to load my modules dynamically based on the value given in the xml. It will help us to plug-in the feature to the application dynamically. It may not be right forum but your support and help are much appreciated on this.
Create server:
async function bootstrap() {
const server = express();
const app = await NestFactory.create(ApplicationModule, server, {});
app.use(bodyParser.json());
app.setGlobalPrefix('/api');
await app.listen(3000);
}
bootstrap();
Create middleware:
@Middleware()
export class AuthMiddleware implements NestMiddleware {
constructor(
@Inject(constants.logger) private logger: Winston,
){}
resolve(...args: any[]): ExpressMiddleware {
return (req, res, next) => {
this.logger.debug('AuthMiddleware');
next();
};
}
}
Create following module:
export class UsersModule implements NestModule {
configure(consumer: MiddlewaresConsumer): void {
const authRoutes = [{ path: `/api/users`, method: RequestMethod.GET }];
consumer
.apply(AuthMiddleware)
.forRoutes(...authRoutes);
}
}
Create following controller:
@Controller('users')
export default class UsersController extends BasicController {
@Get()
async getAllUsers() {
console.log('getAllUsers()');
return this.usersService.getAll();
}
}
I expect to see AuthMiddleware in console, but nothing happaned. Why? Because if you have set up global prefix, you shouldnt use this part (in my case its /api
) when configuring middlewares.
On my MacBook Pro, scrolling with the trackpad anywhere in the lefthand side table of contents tree is extremely jerky, while in the primary content area it is fluid.
It's likely related to a scroll or wheel event being fired too often.
[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
As a user, I would like to see the Validation section.
For Tooling issues:
- Node version: XX
- Platform:
Others:
I found a small typo in the gateways doc examples in the Asynchronous responses section.
The code in the example is as followed:
@SubscribeMessage('events')
onEvent(client, data: any: Observable<WsResponse<number>> {
const event = 'events';
const response = [1, 2, 3];
return from(response).pipe(
map(data => ({ event, data })),
);
}
The onEvent function seems like its missing its closing )
character after data: any
.
Issue within the code is found at this line
thanks for all the work done on NestJs, so far loving the framework π π
Can't reproduce the issue anymore.
Yesterday i started to work on graphql integration of nestjs. On a different laptop today i opened the docs page on chrome to find that no docs for graphql. Opened the website on firefox on same laptop and saw the new docs website. so, I check the cookies and find that it's keeping the page in a folder named "service worker" and keeps serving that. I am not well versed in service workers and offline caching, but, stale docs page (about 1 month old) is not good. Didn't capture any screenshots before i cleared the cookies. Please ignore if already taken action.
P.S. - Awesome project :) keep up the good work :)
[ ] Regression
[ ] Bug report
[ ] Feature request
[ ] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
As a user, I would like to see passing gRPC metadata example
For Tooling issues:
- Node version: XX
- Platform:
Others:
I was trying to use the new Passport module in order to implement the whole OAuth2 Process (Google Login). However I was not sure how I am supposed to handle the callback where one would usually call passport.authenticate()
.
Can you add documentation which shows an OAuth2 login via Google (or some other provider)?
[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
As a user, I would like to see caching version
For Tooling issues:
- Node version: XX
- Platform:
Others:
[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
The documentation should be more detailed about how the microservice communication works internally.
For Tooling issues:
- Node version: XX
- Platform:
Others:
[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
As a user, I would like to see more passport examples.
nestjs/nest#708
nestjs/nest#833
For Tooling issues:
- Node version: XX
- Platform:
Others:
I have some problem like here nestjs/nest#315. Because docs has wrong info.
Thank in advance.
[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
For Tooling issues:
- Node version: XX
- Platform:
Others:
I get an error when running file: http-exception.filter.ts
.
Removing line:
.status(status)
fixes the problem. What for is this line?
Is there a reason why you don't use pipeable operators in the documentation?
[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
As a user, I would like to see higher test coverage of the provided examples (tests as a first class citizen).
For Tooling issues:
- Node version: XX
- Platform:
Others:
Hello there,
after checking out the repo and npm install
ing, when I run $ npm start
I get the following message after which everything stops:
It seems like you're using a project generated using an old version of the Angular CLI.
The latest CLI now uses webpack and has a lot of improvements including a simpler
workflow, a faster build, and smaller bundles.
To get more info, including a step-by-step guide to upgrade the CLI, follow this link:
https://github.com/angular/angular-cli/wiki/Upgrading-from-Beta.10-to-Beta.14
I don't have anglular-cli installed globally, so it comes directly from the package itself.
Has anyone already encountered this? Am I doing something wrong?
[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
The docs for Execution Context say that it can be used to create CLI commands to run in CRON jobs, but when using the example inside a file in the src
folder (where the rest of my code is):
async function bootstrap() {
const app = await NestFactory.createApplicationContext(ApplicationModule);
// logic...
}
bootstrap();
it fails when bootstrapping the application with this error:
AlreadyHasActiveConnectionError: Cannot create a new connection named "default", because connection with such name already exist and it now has an active connection session.
It would be awesome to have proper documentation on how to build CLI commands to run in CRON jobs. I don't know if currently is supported by NestJS but having support for commands like Symfony would be amazing too.
For Tooling issues:
- Node version: XX
- Platform:
Others:
I have been trying to find an immediate way to limit the scope (number/type of of fields) of the response, according to the role of the user requesting. I understand that the CanActivate() function can only return true or false to controller, and cannot be used to interact with services.
Interceptors could be used, but rather than overriding the stream, I would just need to call 2 (or more) different service functions, for a specific controller route, according to properties of the request / context.
What is the proper (go-to) way of doing it in nestjs?
Thank you and kind regards,
M
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.