cd
sudo apt install nodejs
Sevidor com NodeJs e Typescript
mkdir server
cd server
npm init -y
npm i express ts-node
npm i typescript ts-node-dev @types/express -D
npx tsc --init
mkdir src uploads
cd ..
npx ts-node-dev src/server.ts
dentro de package.json em scripts pode ser add os comando de execucao do shell
Banco de dados com Knex
cd server
npm i knex
touch knexfile.ts
cd src
mkdir database
cd database
mkdir migrations seeds
touch connection.ts
cd ../../..
import knex from 'knex';
import path from 'path';
const connection = knex ({
client: 'sqlite3',
connection: {
filename: path.resolve(__dirname, 'database.sqlite'),
},
useNullAsDefault: true
});
export default connection;
import path from 'path';
module.exports = {
client: 'sqlite3',
connection: {
filename: path.resolve(__dirname, 'src', 'database', 'database.sqlite'),
},
migrations: {
directory: path.resolve(__dirname, 'src', 'database', 'migrations'),
},
seeds: {
directory: path.resolve(__dirname, 'src', 'database', 'seeds')
},
useNullAsDefault: true
};
npx knex --knexfile knexfile.ts migrate:latest
Dentro da pasta migrations crie os arquivos para criação de tabelas SQL. Utilize 00_nomeDaPrimeiraTabela para criar na ordem correta
npx knex --knexfile knexfile.ts seed:latest
Dentro da pasta seeds será incluido os arquivos para criação de dados iniciais de alguma tabela SQL já criada.
Roteamento com Express
cd server
npm i express
touch routes.ts
cd src
mkdir controllers
cd ../..
npx ts-node src/server.ts
Web com ReactJs e Typescript
cd origem
npx create-react-app web --template=typescript
cd web
rm -rf favicon.icon logo192.png logo512.png manifest.json robots.txt
cd ..
rm -rf README.md
cd src
rm -rf logo.svg serviceWorker.ts setupTests.ts App.test.tsx index.css
touch routes.tsx
mkdir pages services
cd ../..
npm start