express typescript
// Follow the below steps and you good to go easily
// create a new folder and open a terminal on that folder and type below commands
npm init-y
yarn add -D @types/node typescript ts-node
npx tsconfig.json
// open package.json and add in scripts
"start": "ts-node src/index.ts",
// create new folder src/index.ts ..... open - index.ts
console.log("Hello TypeScript");
//// And type below cmd for start....
yarn start
//// DONE!!!!!!!
0
7
npm install express @types/express
Thank you!
7
0
0
7
// it can vary a lot, but this is a beggining
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "./dist",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.test.ts"]
}
Thank you!
7
0
5
1
import { expect } from "chai"
import chai from "chai"
import chaiHttp from "chai-http"
chai.use(chaiHttp);
import express from "express"
import { createHttpTerminator, HttpTerminatorConfig } from "http-terminator"
const testServer: express.Application = express()
let serverRef, httpTerminator: any
describe('Test Description', () => {
before(() => {
testServer.get('/toto', (req, res) => {
res.send('Hello World')
})
testServer.get('/tata', (req, res) => {
res.send('Hello tata')
})
serverRef = testServer.listen(3000, function () {
// console.log('App is listening on port 3000!');
});
httpTerminator = createHttpTerminator({ server: serverRef });
})
after(async () => {
await httpTerminator.terminate();
})
it('test toto', (done) => {
chai.request('http://localhost:3000')
.get('/toto')
.end(function(err, res) {
expect(res).to.have.status(200);
expect(res.text).to.eq('Hello World');
done();
});
})
it('test tata', (done) => {
chai.request('http://localhost:3000')
.get('/tata')
.end(function(err, res) {
expect(res).to.have.status(200);
expect(res.text).to.eq('Hello tata');
done();
});
})
})
Thank you!
1
0
3.83
7
try this config for nodejs + typescript using babel
https://pastebin.com/TR4BXPqL
Thank you!
7
0
3.75
7
import * as express from 'express'
Thank you!
7
0
Are there any code examples left?
New code examples in category Other
-
Other 2023-03-27 22:50:10 how to select the whole line in vscode with keyboard shortcut
-
Other 2022-03-27 22:45:24 income of a web developer
-
Other 2022-03-27 22:35:01 \pyrcc_main.py: File does not exist 'resources.qrc'
-
Other 2022-03-27 22:30:45 rick roll embed code
-
Other 2022-03-27 22:20:08 Circuit_04_Potentiometer
-
Other 2022-03-27 22:20:05 iterative power
-
Other 2022-03-27 22:15:11 flutter run all
-
Other 2022-03-27 22:10:05 when is karlson release
-
Other 2022-03-27 22:10:02 wp .htaccess example
-
Other 2022-03-27 22:00:08 bash pause in file read line by line