refactored the app export. Update readme.
This commit is contained in:
parent
c3435a5e81
commit
ea4f5b6ede
40
README.md
Normal file
40
README.md
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# README.md Generator for Node.js Application
|
||||||
|
|
||||||
|
## Setting up the Application
|
||||||
|
|
||||||
|
To set up this Node.js application, follow the instructions below:
|
||||||
|
|
||||||
|
1. **Copy `.env.example` to `.env**
|
||||||
|
Open your terminal and navigate to your project's root directory.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cp .env.example .env
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Modify the `.env` file if you wish. The `DB_URL` should already be set
|
||||||
|
correctly.
|
||||||
|
|
||||||
|
3. Start the postgres database:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Install the packages
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ npm i
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Run the tests
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ npm run test
|
||||||
|
```
|
||||||
|
|
||||||
|
6. Start the Express application.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ npm run serve
|
||||||
|
```
|
||||||
|
|
@ -5,7 +5,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "node ./src/index.js",
|
"serve": "node ./src/index.js",
|
||||||
"test": "node --experimental-vm-modules node_modules/.bin/jest"
|
"test": "node --experimental-vm-modules node_modules/.bin/jest --detectOpenHandles --force-exit"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { db } from './db';
|
import db from './db.js';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* utility function to either get the value in the post data
|
* utility function to either get the value in the post data
|
||||||
@ -15,8 +15,6 @@ function valOrMissing(data, key, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function createApp() {
|
|
||||||
|
|
||||||
// Creating an instance of Express
|
// Creating an instance of Express
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(express.json()) // for parsing application/json
|
app.use(express.json()) // for parsing application/json
|
||||||
@ -38,5 +36,4 @@ export function createApp() {
|
|||||||
return res.status(200).send({ "note": note[0] });
|
return res.status(200).send({ "note": note[0] });
|
||||||
});
|
});
|
||||||
|
|
||||||
return app;
|
export default app;
|
||||||
}
|
|
@ -1,9 +1,6 @@
|
|||||||
import { db } from "./db";
|
import app from "./app";
|
||||||
import { createApp } from "./app";
|
|
||||||
import request from "supertest";
|
import request from "supertest";
|
||||||
|
|
||||||
const app = createApp();
|
|
||||||
|
|
||||||
const note = {
|
const note = {
|
||||||
title: 'Test Note',
|
title: 'Test Note',
|
||||||
text: 'This is a test note.'
|
text: 'This is a test note.'
|
||||||
|
@ -7,7 +7,7 @@ if (!process.env.DB_URL) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Creating an instance of Knex
|
// Creating an instance of Knex
|
||||||
export const db = knex({
|
export default knex({
|
||||||
client: 'postgres',
|
client: 'postgres',
|
||||||
connection: process.env.DB_URL
|
connection: process.env.DB_URL
|
||||||
});
|
});
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
// Importing express
|
// Importing express
|
||||||
import { createApp } from './app';
|
|
||||||
|
import app from "./app.js";
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
const app = createApp();
|
|
||||||
// Start the Express server
|
|
||||||
app.listen(3000, () => {
|
app.listen(3000, () => {
|
||||||
console.log('Server started on port 3000');
|
console.log('Server started on port 3000');
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Exporting the app
|
|
||||||
export default app;
|
|
Loading…
Reference in New Issue
Block a user