You need to set up your development environment before you can do anything.
Install Node.js and NPM
- on OSX use homebrew
brew install node
Install a MySQL database.
If you work with a mac, we recommend to use homebrew for the installation.
Go to the project dir and run the following script.
npm install
This will install all the dependencies needs for the project
npm i -g typescript
This will install typescript globally
tsc --init
This will will create a typescript config file
tsconfig.json
npm i -g sequelize-cli
This will install sequelize-cli globally
sequelize init
This will create a config.json file inside the config folder.
We can additionally specify in which folder we have to create the models, migrations and seeds in the .sequelizerc
file.
- Run
npx sequelize-cli model:generate --name User --attributes firstName:string
The above command will create a User model with the firstname attribute(field in the table)
- Run
npx sequelize-cli db:migrate
to run all migrations.
- Run
npx sequelize-cli db:seed:all
to seed your seeds into the database.
- modify the script part in the package.json as follows:
"start": "node dist/app.js",
"dev": "nodemon src/app.ts",
"build": "tsc -p ."
When run the build command, typscript will create the build in the dist folder. Then if we run the start command it will take the compiled js from the dist folder. If we just need to the application in dev mode then it will take the server file (
app.ts
) and run the application on a port
- Run
npm run dev
to start nodemon with ts-node, to serve the app. - The server address will be displayed to you as
http://127.0.0.1:5555
- Run
npm run build
to generated all JavaScript files from the TypeScript sources (There is also a vscode task for this calledbuild
). - To start the builded app located in
dist
usenpm start
.
DBHOST=localhost
DB=<db_name>
DBUSER=<db_user>
DBPASSWORD=<db_password>
AWS_ACCESS_KEY=
Replace with the db credentials and place in the root
As the db models and migrations created by the sequlize cli is based on ES5, the code on that part wont be in typescript. Instead it will follow the ES5 structure.