-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Below will describe the basic setup of an application and how to set it up.
1. First create a new directory and then initialise it.
Create your folder, open it then run the below command fill out the details.
npm init
2. Create your tsconfig.json file.
You can use the below file:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./src",
"declaration": true,
"sourceMap": true,
"noImplicitAny": false,
"noImplicitThis": false,
"moduleResolution": "node",
"strict": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"removeComments": false,
"resolveJsonModule": true,
"types": ["node"],
"typeRoots": [ "node_modules/@types" ]
}
}
3. Now install the packages.
Use the command below to save the package to your package.json
, we suggest saving it using the --save
flag because it's an active and required dependency for production.
npm install --save rewyre
npm install --save-dev typescript ts-node @types/node
4. Create your scripts.
The below will give you two new commands to add to the scripts section of the package.json
.
"scripts": {
"start": "node --max_old_space_size=2048 ./dist/application.js",
"build": "rm -rf dist/ && node_modules/.bin/tsc",
"dev": "node -r ts-node/register --max_old_space_size=2048 ./src/application.ts",
}
The above has given you three new commands, the "dev" command would be called as: npm run dev
and this will run the application as TypeScript using the ts-node
execution and REPL package. The "build" command will call the typescript compiler to compile the project into the ./dist
folder, and lastly, the "start" command will run the build project, using standard node.
5. Creating your entry file.
We need to create a ./src
folder and then create our entry file.
mkdir ./src
touch ./src/application.ts
Now add the following to your ./src/application.ts
file.
// Import the rewyre framework.
import { Framework } from 'rewyre';
// Create an async closure function, we do this as we need to call
// await functions and it's easier to do it like the below.
(async () => {
// Let's create our application instance, we will override the default `3000` port and use `8080`.
const application: Framework = new Framework({
port: 8080,
});
// Start the application.
await application.start();
})();